# Filename: PyGObject_RadioButtonDemo
# Python programm using GTK, the GIMP ToolKit for creating graphical user interfaces
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class RadioButtonWindow(Gtk.Window):
def __init__(self):
super().__init__(title="RadioButton Demo")
self.set_border_width(10)
vbox = Gtk.Box(spacing=6)
self.add(vbox)
button1 = Gtk.RadioButton.new_with_label_from_widget(None, "Wikipedia")
button1.connect("toggled", self.on_button_toggled, "WP")
vbox.pack_start(button1, False, False, 0)
button2 = Gtk.RadioButton.new_from_widget(button1)
button2.set_label("Commons")
button2.connect("toggled", self.on_button_toggled, "Commons")
vbox.pack_start(button2, False, False, 0)
button3 = Gtk.RadioButton.new_with_mnemonic_from_widget(button1, "Wiki_data")
button3.connect("toggled", self.on_button_toggled, "WD")
vbox.pack_start(button3, False, False, 0)
def on_button_toggled(self, button, name):
if button.get_active():
state = "on"
else:
state = "off"
print("Button", name, "was turned", state)
win = RadioButtonWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()