繁体   English   中英

PyGTK单选按钮都经过检查

[英]PyGTK radio buttons are all checked

我正在尝试使用PyGTK创建一个Window,它基于一个字符串数组动态创建单选按钮(一个看起来像[“选项1”,“选项2”,“选项3”]的数组将创建3个单选按钮带有与数组元素相对应的标签。

我的问题是所有单选按钮都被选中,它们无法取消选中,因此我无法连接到“切换”事件。 我看不出我做错了什么。

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

调用get_active()的print语句总是打印为True

[编辑]我正在加载Gtk

from gi.repository import Gtk

这是我的窗口

看来在较新的版本中你使用静态方法Gtk.RadioButton.new_with_label_from_widget而不是你当前用来创建单选按钮的方法(这对于pygtk 2.0版本工作正常)。 尝试将Gtk.RadioButton更改为代码中的Gtk.RadioButton.new_with_label_from_widget
希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM