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)

Inherits: LayoutControl
Example
Fluent ToggleButton
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)

Properties
autofocusclass-attributeinstance-attribute
autofocus: bool = FalseWhether this button should be focused on initial display.
contentclass-attributeinstance-attribute
content: StrOrControl | None = NoneThe 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.