InterviewSolution
| 1. |
When I Connect To A Signal, My Handler Gets Called But Reports "xxx Takes No Arguments (1 Given)"? |
|
Answer» 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): 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. 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): 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. |
|