PyGtk - 激活组合框
如果我在 pyGTK 中有一个组合框,并且想要设置一个字符串列表,然后单击一个字符串激活一个命令,我该怎么做?
目前我有:
self.combo_key = gtk.Combo()
self.combo_key.set_popdown_strings(self.keys)
self.combo_key.entry.set_text(db.keys()[0])
self.combo_key.entry.connect("activate", self.key_sel)
但是 "activate"
仅在选择后调用,然后按 Enter 键。我还收到了 gtk.Combo()
的弃用警告,但找不到任何有关使用 gtk.ComboBoxEntry()
的帮助,
有帮助吗?
If I have a combo box in pyGTK and would like to set a list of strings and then on clicking on one activate a command how would I do it?
At the moment I have:
self.combo_key = gtk.Combo()
self.combo_key.set_popdown_strings(self.keys)
self.combo_key.entry.set_text(db.keys()[0])
self.combo_key.entry.connect("activate", self.key_sel)
But "activate"
only calls after selection, and then by pressing enter. I'm also getting a deprecation warning for gtk.Combo()
but cannot find any help on using gtk.ComboBoxEntry()
Any help guys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
gtk.ComboBox
而不是gtk.Combo
,因为后者已被弃用,取而代之的是前者。要初始化,您可以编写如下代码:现在连接到组合框的
changed
信号,并使用其get_active()
方法来请求所选择的项目。正如您可能从这个解释中猜到的那样,ComboBox 并不是专门为此目的而设计的。您可能想使用
gtk.Menu
。Try using a
gtk.ComboBox
instead ofgtk.Combo
, since the latter is deprecated in favor of the former. To initialise, you can you code like:Now you connect to the
changed
signal of thecombobox
and use itsget_active()
method to ask for the item that was selected.As you might guess from this explanation, the ComboBox isn't exactly made for this purpose. You probably want to use
gtk.Menu
.