I'm trying to create a Window using PyGTK that has dynamically created radio buttons based of an array of Strings (an a array that looks like ["option 1", "option 2", "option 3"] would create 3 radio buttons with labels respective to the array elements).
My problem is that all the Radio buttons are checked, they cannot be unchecked, and therefore I can't connect to the "toggled" event. I can't see what I'm doing wrong.
class SelectionWindow(Gtk.Window):
def __init__(self):
global options
super(EmulatorSelectionWindow, self).__init__()
self.set_title("Select an Emulator")
box = Gtk.VBox(spacing=10)
group = Gtk.RadioButton(None, "test radio")
box.pack_start(group, True,True, 0)
for option in options:
r = Gtk.RadioButton(group, option)
r.connect("toggled", self.on_radio_selection, option)
print "before setting active", r.get_active()
r.set_active(False)
print "after setting active", r.get_active()
box.pack_start(r,True, True, 0)
self.add(box)
def on_radio_selection(self, widget, data=None):
print "toggle pressed", data
The print statements that call get_active(), always print True
[Edit] I am loading the Gtk by
from gi.repository import Gtk
It appears that in newer version you have use static method Gtk.RadioButton.new_with_label_from_widget instead of the method you are using currently to create radio button (which works fine for pygtk 2.0 versions). Try changing Gtk.RadioButton
to Gtk.RadioButton.new_with_label_from_widget
in the code.
Hope this helps!