为什么Gtk.Dialog响应信号吐出2个参数而不是3个?

时间:2013-04-26 12:22:52

标签: python gtk3 glade pygobject

我正在尝试学习Python和PyGObject,所以我写了一个简单的程序,添加用户输入的两个数字并显示结果并使用Glade创建用户界面。

enter image description here

enter image description here

它还有一个关于对话框。但是,每当我想处理来自response的{​​{1}}信号(当我点击关闭按钮或窗口标题中的about_dialog时给出)时,解释器会给出x }。

以下是full code的相关部分,其中包含Glade文件here

TypeError

当函数在下面并且user_data设置为labelresult时,Label对象使用Glade来保存加法结果first_number + second_number,因为它可以在this屏幕截图中看到:

...
class GUI():
...
    signalHandler = {
            'on_main_window_destroy': Gtk.main_quit,
            'on_button_quit_clicked': self.on_button_quit_clicked,
            'on_button_about_clicked': self.on_button_about_clicked,
            'on_button_add_clicked': self.on_button_add_clicked,
            'about_response':self.about_response
    }
    self.builder.connect_signals(signalHandler)
...
    def about_response(self, widget, response_id, user_data=None):
    # self.about_dialog.destroy()
    print(widget, response_id, user_data)
    print('About dialog closed.')
....

以下输出为:

def about_response(self, widget, response_id, user_data):

当我print(self, widget, response_id, user_data) Output: TypeError: about_response() takes exactly 4 arguments (3 given) 时,输出为:

user_data=None

如果没有在glade中设置user_data,则输出为:

(<__main__.GUI instance at 0xb6dd458c>,
<Label object at 0x99c393c (GtkLabel at 0x9aeaa28)>, -6, None)

因此,它只会更改GtkDialog *对话框参数。我无法理解这一点,因为我可以看到here,信号(<__main__.GUI instance at 0xb6d3e58c>, <AboutDialog object at 0xa09711c (GtkAboutDialog at 0xa191040)>, -6, None) 会抛出3个参数,但在这种情况下,它只会抛出2个。

这里发生了什么,为什么Gtk.Dialog响应信号吐出2个参数而不是3个?

0 个答案:

没有答案