#!/usr/bin/env python
# --*-- coding:utf-8 --*--
# example packbox.py
import gi
gi.require_version('Gtk', '3.0')
#from gi.repository.Gtk import *
import gi.repository.Gtk as gtk
class RadioButtonWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self, title="RadioButton Demo")
self.set_border_width(10)
hbox = gtk.Box(spacing=6)
self.add(hbox)
button1 = gtk.RadioButton.new_with_label_from_widget(None, "Button 1")
button1.connect("toggled", self.on_button_toggled, "1")
hbox.pack_start(button1, False, False, 0)
button2 = gtk.RadioButton.new_from_widget(button1)
button2.set_label("Button 2")
button2.connect("toggled", self.on_button_toggled, "2")
hbox.pack_start(button2, False, False, 0)
button3 = gtk.RadioButton.new_with_mnemonic_from_widget(button1,
"B_utton 3")
button3.connect("toggled", self.on_button_toggled, "3")
hbox.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("delete-event", gtk.main_quit)
win.show_all()
gtk.main()