Skip to main content

ToggleSwitch

A Fluent toggle switch, for turning an option on or off with an immediate effect.

Example:

fluent.ToggleSwitch(label="Wi-Fi", value=True)
fluent.ToggleSwitch(label="Bluetooth")
ToggleSwitch
ToggleSwitch

Inherits: LayoutControl

Properties

  • autofocus - Whether this switch should be focused on initial display.
  • label - The label shown next to this switch.
  • label_first - Whether label is shown before the switch instead of after it.
  • value - Whether this switch is on.

Events

Example​

Fluent ToggleSwitch​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


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

def handle_change(e: ft.Event[fluent.ToggleSwitch]):
status.value = "Wi-Fi is on" if e.control.value else "Wi-Fi is off"

status = ft.Text("Wi-Fi is off")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
fluent.ToggleSwitch(label="Wi-Fi", on_change=handle_change),
fluent.ToggleSwitch(
label="Bluetooth", label_first=True, value=True
),
fluent.ToggleSwitch(label="Disabled", disabled=True),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
toggle_switch
Turning Wi-Fi on

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this switch should be focused on initial display.

labelclass-attributeinstance-attribute​

label: StrOrControl | None = None

The label shown next to this switch. Clicking it toggles the switch.

label_firstclass-attributeinstance-attribute​

label_first: bool = False

Whether label is shown before the switch instead of after it.

valueclass-attributeinstance-attribute​

value: bool = False

Whether this switch is on.

Events​

on_changeclass-attributeinstance-attribute​

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

Called when value changes.

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