Skip to main content

ToggleButton

A Fluent button that can be switched on and off, filled with the accent color while checked.

Example:

fluent.ToggleButton("Bold", on_change=lambda e: print(e.data))
fluent.ToggleButton("Italic", checked=True)
ToggleButton
ToggleButton

Inherits: LayoutControl

Properties

  • autofocus - Whether this button should be focused on initial display.
  • checked - Whether this button is on.
  • content - The button's label.

Events

Example​

Fluent ToggleButton​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


def main(page: ft.Page):
page.title = "Fluent ToggleButton"

def handle_change(e: ft.Event[fluent.ToggleButton]):
preview.weight = ft.FontWeight.BOLD if e.control.checked else None
status.value = "Bold on" if e.control.checked else "Bold off"

preview = ft.Text("The quick brown fox", size=18)
status = ft.Text("Bold off")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
fluent.ToggleButton("Bold", on_change=handle_change),
preview,
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
toggle_button
Turning bold on

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this button should be focused on initial display.

checkedclass-attributeinstance-attribute​

checked: bool = False

Whether this button is on.

contentclass-attributeinstance-attribute​

content: StrOrControl | None = None

The button's label.

If a string is provided, it is wrapped in a Text control.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[ToggleButton] | None = (
    None
)

Called when checked changes.

The data property of the event handler argument contains the new value.