I am trying to learn Python and PyGObject, so I have written a simple program that adds user inputted two numbers and shows the result and created the user interface using Glade.
It has also an about dialog. However, whenever I want to process response
signal coming from the about_dialog
, which is given when I hit the Close button or the x
in the window title, the interpreter gives TypeError
.
Here is the relevant part of the full code which has the Glade file here:
...
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.')
....
When the function is below and when the user_data is set to labelresult Label object, which holds the addition result first_number + second_number, using Glade as it can be seen in this screenshot:
def about_response(self, widget, response_id, user_data):
Output of the below is:
print(self, widget, response_id, user_data)
Output: TypeError: about_response() takes exactly 4 arguments (3 given)
When I make user_data=None
, the output is:
(<__main__.GUI instance at 0xb6dd458c>,
<Label object at 0x99c393c (GtkLabel at 0x9aeaa28)>, -6, None)
Without setting the user_data in glade, the output is:
(<__main__.GUI instance at 0xb6d3e58c>,
<AboutDialog object at 0xa09711c (GtkAboutDialog at 0xa191040)>, -6, None)
So, it only changes the GtkDialog *dialog parameter. I cannot understand this, because as I can see here, the signal response
throws 3 parameters, however in this case, it throws only 2.
What is going on here, why does Gtk.Dialog response signal spits 2 arguments instead of 3?