File: Tutorial_13_gtk_botones_de_radio.py

package info (click to toggle)
sugar-pippy-activity 75-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,660 kB
  • sloc: python: 5,786; makefile: 16; sh: 6
file content (39 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class PyApp(Gtk.Window):

    def __init__(self):
        super(PyApp, self).__init__()

        self.set_title('Botones de radio')
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_size_request(250, 150)

        vbox = Gtk.VBox()

        button1 = Gtk.RadioButton(group=None, label='Boton 1')
        button1.connect('toggled', self._activate_cb, 1)
        vbox.pack_start(button1, True, True, 2)

        button2 = Gtk.RadioButton(group=button1, label='Boton 2')
        button2.connect('toggled', self._activate_cb, 2)
        vbox.pack_start(button2, True, True, 2)

        button3 = Gtk.RadioButton(group=button1, label='Boton 3')
        button3.connect('toggled', self._activate_cb, 3)
        vbox.pack_start(button3, True, True, 2)

        self.add(vbox)
        self.show_all()

        self.connect('destroy', Gtk.main_quit)

    def _activate_cb(self, button, button_index):
        if button.get_active():
            print('Has seleccionado el boton %d' % button_index)


PyApp()
Gtk.main()