[Tutor] binding problem
Peter Otten
__peter__ at web.de
Thu Nov 3 15:08:31 CET 2011
Chris Hare wrote:
> Thanks for the advice. When I do that, I get this error
>
> Exception in Tkinter callback
> Traceback (most recent call last):
> File
>
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-
tk/Tkinter.py",
> line 1410, in __call__
> return self.func(*args)
> TypeError: focus_set() takes exactly 1 argument (2 given)
>
> In situations like this where the function isn't one you wrote, how to you
> debug these?
In this case there is not much to debug, the error message says it all: you
have an extra argument that the focus_set() method doesn't accept. The
simplest way to drop that argument is to wrap the method call:
def focus_set(event): # only one arg because it's a function, not a method
self.login_userid.focus_set()
self.list.bind("<Button-1>", focus_set)
This is sometimes written with a lambda function
self.list.bind("<Button-1>", lambda event: self.login_userid.focus_set())
If you wanted to learn more about that extra argument you could temporarily
replace the callback with something that can give you the necessary
information, e. g.
def inspect_args(*args):
for arg in args:
print arg
print vars(arg)
self.list.bind("<Button-1>", inspect_args)
As a last resort and an idea almost too revolutionary to mention in public,
you could read some tutorial or documentation...
More information about the Tutor
mailing list