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()
|