Debian Codegraph @

docs/tutorials/gtk4/controls/buttons.rst

raw
1 .. currentmodule:: gi.repository
2
3 Buttons
4 =======
5
6 Button
7 ------
8 The Button widget is another commonly used widget. It is generally used to
9 attach a function that is called when the button is pressed.
10
11 The :class:`Gtk.Button` widget can hold any valid child widget. That is it can
12 hold most any other standard :class:`Gtk.Widget`.
13 The most commonly used child is the :class:`Gtk.Label`.
14 Normally you will use :attr:`Gtk.Button.props.label` to set the button label, or
15 :attr:`Gtk.Button.props.icon_name` if you want an icon instead.
16
17 Usually, you want to connect to the button's ``clicked`` signal which is emitted
18 when the button has been pressed and released.
19
20 Example
21 ^^^^^^^
22
23 .. image:: images/button.png
24
25 .. literalinclude:: examples/button.py
26 :linenos:
27
28
29 ToggleButton
30 ------------
31
32 A :class:`Gtk.ToggleButton` is very similar to a normal :class:`Gtk.Button`,
33 but when clicked they remain activated, or pressed, until clicked again.
34 When the state of the button is changed, the `toggled` signal is emitted.
35
36 To retrieve the state of the :class:`Gtk.ToggleButton`, you can use
37 :attr:`Gtk.ToggleButton.props.active`. This returns ``True`` if the button
38 is "down". You can also set the toggle button's state, with
39 :attr:`Gtk.ToggleButton.props.active`. Note that, if you do this, and the state
40 actually changes, it causes the "toggled" signal to be emitted.
41
42 Example
43 ^^^^^^^
44
45 .. image:: images/togglebutton.png
46
47 .. literalinclude:: examples/togglebutton.py
48 :linenos:
49
50
51 LinkButton
52 ----------
53 A :class:`Gtk.LinkButton` is a :class:`Gtk.Button` with a hyperlink, similar
54 to the one used by web browsers, which triggers an action when clicked. It is
55 useful to show quick links to resources.
56
57 The URI bound to a :class:`Gtk.LinkButton` can be set specifically using
58 :attr:`Gtk.LinkButton.props.uri`.
59
60 Example
61 ^^^^^^^
62
63 .. image:: images/linkbutton.png
64
65 .. literalinclude:: examples/linkbutton.py
66 :linenos: