| FAQ Index - Search - Recent Changes - Everything - Add entry |
3.1. When I connect to a signal, my handler gets called but reports "XXX takes no arguments (1 given)"
Signal callbacks have specific signatures. This means that when a signal is emitted, it will send to the callback function a number of parameters. The first parameter is the widget which generated the event, and the rest vary depending on what signal is being emitted.
To handle a callback, your function signature, therefore, must take this into account. Often you don't even want to use any of the arguments, just trigger an action on a certain signal; an easy way to do this is using a variable argument list (*args) and ignoring them in your method:
def on_win_delete(*args):
print "Deleted, and who cares why"
w = gtk.Window()
w.connect("delete-event", on_win_delete)
If you are attaching to a method, be sure to provide the usual self in the method definition, and specifying self.on_foo_signal as the function to attach to.
