我想把2个ComboBox实例传递给a方法并在那里使用它们(例如,打印它们的活动选择)。我有一些类似的东西:
class GUI():
...
def gui(self):
...
combobox1 = gtk.combo_box_new_text()
# code for inserting some values into the combobox
combobox2 = gtk.combo_box_new_text()
# code for inserting some values into the combobox
btn_new = gtk.Button("new")
btn_new.connect("clicked", self.comboprint)
def comboprint(self):
# do something with the comboboxes - print what is selected, etc.
如何将combobox1和combobox2传递给方法“comboprint”,以便在那里使用它们?使它们成为类域(自我组合框1, 自我组合框2)唯一的办法是?在
我会用另一种方法来解决这个问题,通过创建combbox1和combobox2类变量,如下所示:
这样做的好处是,当另一个函数需要处理这些组合框时,它们可以这样做,而不必将组合框作为参数传递给每个函数。在
做这样的事情:
在你的回调中
^{pr2}$comboprint
应该是这样的:相关问题 更多 >
编程相关推荐