Gtk.ToggleButton¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Button (16), Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (17), Gtk.Buildable (1), Gtk.Actionable (5)
- Structs:
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Button (2), Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9), Gtk.Actionable (4)
|
Properties¶
- Inherited:
Gtk.Button (6), Gtk.Widget (35), Gtk.Accessible (1), Gtk.Actionable (2)
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/en |
|||
w |
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
Emitted whenever the |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
button |
r |
Class Details¶
- class Gtk.ToggleButton(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Shows a button which remains “pressed-in” when clicked.
<picture> <source srcset=”toggle-button-dark.png” media=”(prefers-color-scheme: dark)”> <img alt=”Example GtkToggleButtons” src=”toggle-button.png”> </picture>
Clicking again will cause the toggle button to return to its normal state.
A toggle button is created by calling either [ctor`Gtk`.ToggleButton.new] or [ctor`Gtk`.ToggleButton.new_with_label]. If using the former, it is advisable to pack a widget, (such as a
GtkLabeland/or aGtkImage), into the toggle button’s container. (See [class`Gtk`.Button] for more information).The state of a
GtkToggleButtoncan be set specifically using [method`Gtk`.ToggleButton.set_active], and retrieved using [method`Gtk`.ToggleButton.get_active].- Grouping
Toggle buttons can be grouped together, to form mutually exclusive groups - only one of the buttons can be toggled at a time, and toggling another one will switch the currently toggled one off.
To add a
GtkToggleButtonto a group, use [method`Gtk`.ToggleButton.set_group].- CSS nodes
GtkToggleButtonhas a single CSS node with name button. To differentiate it from a plainGtkButton, it gets the.togglestyle class.- Accessibility
GtkToggleButtonuses the [enum`Gtk`.AccessibleRole.toggle_button] role.- Creating two
Gtk.ToggleButtonwidgets.
```c static void output_state (
Gtk.ToggleButton*source,objectuser_data) { g_print (“Toggle button “%s” is active: %s”,Gtk.Button.get_label(GTK_BUTTON (source)),Gtk.ToggleButton.get_active(source) ? “Yes” : “No”); }static void make_toggles (void) {
Gtk.Widget*window, *toggle1, *toggle2;Gtk.Widget*box; conststr*text;window =
Gtk.Window.new(); box =Gtk.Box.new(Gtk.Orientation.VERTICAL, 12);text = “Hi, I’m toggle button one”; toggle1 =
Gtk.ToggleButton.new_with_label(text);g_signal_connect (toggle1, “toggled”, G_CALLBACK (output_state),
None);Gtk.Box.append(GTK_BOX (box), toggle1);text = “Hi, I’m toggle button two”; toggle2 =
Gtk.ToggleButton.new_with_label(text); g_signal_connect (toggle2, “toggled”, G_CALLBACK (output_state),None);Gtk.Box.append(GTK_BOX (box), toggle2);Gtk.Window.set_child(GTK_WINDOW (window), box);Gtk.Window.present(GTK_WINDOW (window)); } ```- classmethod new()[source]¶
- Returns:
a new toggle button.
- Return type:
Creates a new toggle button.
A widget should be packed into the button, as in [ctor`Gtk`.Button.new].
- classmethod new_with_label(label)[source]¶
- Parameters:
label (
str) – a string containing the message to be placed in the toggle button.- Returns:
a new toggle button.
- Return type:
Creates a new toggle button with a text label.
- classmethod new_with_mnemonic(label)[source]¶
- Parameters:
label (
str) – the text of the button, with an underscore in front of the mnemonic character- Returns:
a new
GtkToggleButton- Return type:
Creates a new
GtkToggleButtoncontaining a label.The label will be created using [ctor`Gtk`.Label.new_with_mnemonic], so underscores in label indicate the mnemonic for the button.
- get_active()[source]¶
- Returns:
whether the button is pressed
- Return type:
Queries a
GtkToggleButtonand returns its current state.Returns
Trueif the toggle button is pressed in andFalseif it is raised.
- set_active(is_active)[source]¶
-
Sets the status of the toggle button.
Set to
Trueif you want theGtkToggleButtonto be “pressed in”, andFalseto raise it.If the status of the button changes, this action causes the [signal`Gtk`.ToggleButton::toggled] signal to be emitted.
- set_group(group)[source]¶
- Parameters:
group (
Gtk.ToggleButtonorNone) – anotherGtkToggleButtonto form a group with
Adds self to the group of group.
In a group of multiple toggle buttons, only one button can be active at a time.
Setting up groups in a cycle leads to undefined behavior.
Note that the same effect can be achieved via the [iface`Gtk`.Actionable] API, by using the same action with parameter type and state type ‘s’ for all buttons in the group, and giving each button its own target value.
Signal Details¶
- Gtk.ToggleButton.signals.toggled(toggle_button)¶
- Signal Name:
toggled- Flags:
- Parameters:
toggle_button (
Gtk.ToggleButton) – The object which received the signal
Emitted whenever the
GtkToggleButton’s state is changed.
Property Details¶
- Gtk.ToggleButton.props.active¶
- Name:
active- Type:
- Default Value:
- Flags:
If the toggle button should be pressed in.
- Gtk.ToggleButton.props.group¶
- Name:
group- Type:
- Default Value:
- Flags:
The toggle button whose group this widget belongs to.