I am learning Gtk programming with python from this. But I can not understand what is the reason for the widget
keyword in the following callback definition? Can someone please explain what it does?
def on_button_clicked(self, widget):
print("Hello World")
When the button is clicked, the on_button_clicked method is executed. When this happens, the window and button objects are passed to the method as self
and widget
, respectively. This is useful in cases where one needs to do something with the button, such as getting its state or changing its text.
Without the widget
parameter, the button object would be passed to the method and there wouldn't be a parameter to receive it, and you would get a TypeError.