Gtk.ToggleButton¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Button (16), Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), 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 (34), 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:
A
GtkToggleButton
is a button which remains “pressed-in” when clicked.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
GtkLabel
and/or aGtkImage
), into the toggle button’s container. (See [class`Gtk`.Button] for more information).The state of a
GtkToggleButton
can be set specifically using [method`Gtk`.ToggleButton.set_active], and retrieved using [method`Gtk`.ToggleButton.get_active].To simply switch the state of a toggle button, use [method`Gtk`.ToggleButton.toggled].
- 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
GtkToggleButton
to a group, use [method`Gtk`.ToggleButton.set_group].- CSS nodes
GtkToggleButton
has a single CSS node with name button. To differentiate it from a plainGtkButton
, it gets the.toggle
style class.- Accessibility
GtkToggleButton
uses theGtk.AccessibleRole.TOGGLE_BUTTON
role.- Creating two
Gtk.ToggleButton
widgets.
```c static void output_state (
Gtk.ToggleButton
*source,object
user_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
GtkToggleButton
containing 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
GtkToggleButton
and returns its current state.Returns
True
if the toggle button is pressed in andFalse
if it is raised.
- set_active(is_active)[source]¶
-
Sets the status of the toggle button.
Set to
True
if you want theGtkToggleButton
to be “pressed in”, andFalse
to 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.ToggleButton
orNone
) – anotherGtkToggleButton
to 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.