如何在PyGTK中向button.connect添加其他参数?

aet*_*ter 4 python pygtk

我想将2个ComboBox实例传递给aa方法并在那里使用它们(例如,打印它们的活动选择).我有类似于以下内容:

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.
Run Code Online (Sandbox Code Playgroud)

如何将combobox1和combobox2传递给方法"comboprint",以便我可以在那里使用它们?让他们成为类字段(self.combobox1,self.combobox2)是唯一的方法吗?

mou*_*uad 10

做这样的事情:

btn_new.connect("clicked", self.comboprint, combobox1, combobox2)
Run Code Online (Sandbox Code Playgroud)

在你的回调中comboprint它应该是这样的:

def comboprint(self, widget, *data):
    # Widget = btn_new
    # data = [clicked_event, combobox1, combobox2]
    ...  
Run Code Online (Sandbox Code Playgroud)