Gtk.Switch¶
Example¶

- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (16), Gtk.Buildable (1), Gtk.Actionable (5)
- Structs:
class |
|
|
|
|
|
|
|
|
Virtual Methods¶
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted to animate the switch. |
|
Emitted to change the underlying state. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.Switch(**kwargs)¶
- Bases:
- Abstract:
No
GtkSwitch
is a “light switch” that has two states: on or off.An example
Gtk.Switch
The user can control which state should be active by clicking the empty area, or by dragging the slider.
GtkSwitch
can also express situations where the underlying state changes with a delay. In this case, the slider position indicates the user’s recent change (represented by the [property`Gtk`.Switch:active] property), while the trough color indicates the present underlying state (represented by the [property`Gtk`.Switch:state] property).Gtk.Switch
with delayed state changeSee [signal`Gtk`.Switch::state-set] for details.
- Shortcuts and Gestures
GtkSwitch
supports pan and drag gestures to move the slider.- CSS nodes
`` switch ├── image ├── image ╰── slider ``
GtkSwitch
has four css nodes, the main node with the name switch and subnodes for the slider and the on and off images. Neither of them is using any style classes.- Accessibility
GtkSwitch
uses theGtk.AccessibleRole.SWITCH
role.- classmethod new()[source]¶
- Returns:
the newly created
GtkSwitch
instance- Return type:
Creates a new
GtkSwitch
widget.
- get_state()[source]¶
- Returns:
the underlying state
- Return type:
Gets the underlying state of the
GtkSwitch
.
Signal Details¶
- Gtk.Switch.signals.activate(switch)¶
- Signal Name:
activate
- Flags:
- Parameters:
switch (
Gtk.Switch
) – The object which received the signal
Emitted to animate the switch.
Applications should never connect to this signal, but use the [property`Gtk`.Switch:active] property.
- Gtk.Switch.signals.state_set(switch, state)¶
- Signal Name:
state-set
- Flags:
- Parameters:
switch (
Gtk.Switch
) – The object which received the signalstate (
bool
) – the new state of the switch
- Returns:
True
to stop the signal emission- Return type:
Emitted to change the underlying state.
The
::state-set
signal is emitted when the user changes the switch position. The default handler calls [method`Gtk`.Switch.set_state] with the value of state.To implement delayed state change, applications can connect to this signal, initiate the change of the underlying state, and call [method`Gtk`.Switch.set_state] when the underlying state change is complete. The signal handler should return
True
to prevent the default handler from running.
Property Details¶
- Gtk.Switch.props.active¶
- Name:
active
- Type:
- Default Value:
- Flags:
Whether the
GtkSwitch
widget is in its on or off state.
- Gtk.Switch.props.state¶
- Name:
state
- Type:
- Default Value:
- Flags:
The backend state that is controlled by the switch.
Applications should usually set the [property`Gtk`.Switch:active] property, except when indicating a change to the backend state which occurs separately from the user’s interaction.
See [signal`Gtk`.Switch::state-set] for details.