Switch#
The switch widget is a clickable button with two stable states, True (on, checked) and False (off, unchecked).
Usage#
import toga
input = toga.Switch()
Reference#
- class toga.widgets.switch.Switch(text=NOT_PROVIDED, id=None, style=None, on_change=None, value=NOT_PROVIDED, enabled=True, factory=None, label=None, on_toggle=None, is_on=None)#
Switch widget, a clickable button with two stable states, True (on, checked) and False (off, unchecked).
- Parameters:
text (str) – Text to be shown next to the switch.
id (str) – AN identifier for this widget.
style (
Style
) – An optional style object. If no style is provided then a new one will be created for the widget.on_change (
callable
) – Function to execute when pressed.value (bool) – Current on or off state of the switch.
enabled (bool) – Whether or not interaction with the button is possible, defaults to True.
- property is_on#
Button Off/On state.
DEPRECATED: renamed as value
- Returns:
True
if on andFalse
if the switch is off.
- property label#
Button Off/On state.
DEPRECATED: renamed as text
- Returns:
True
if on andFalse
if the switch is off.
- property on_change#
The callable function for when the switch is pressed.
- Returns:
The
callable
on_change function.
- property on_toggle#
The callable function for when the switch is pressed.
DEPRECATED: renamed as on_change
- Returns:
The
callable
on_toggle function.
- property text#
Accompanying text label of the Switch.
- Returns:
The label text of the widget as a
str
.
- toggle()#
Reverse the value of Switch.value property from true to false and vice versa.
- property value#
Button Off/On state.
- Returns:
True
if on andFalse
if the switch is off.