[Tutor] binding problem

Chris Hare chare at labr.net
Thu Nov 3 15:41:18 CET 2011


Thanks Peter.  Actually, I have read a bunch of stuff and looked at example code.  The problem in this case is I am using a defined method - focus_set(), which is part of Tkinter and isn't part of my code.  since I am using it in the manner in which I have seen other examples, I am confused about why it is complaining about 2 arguments, when I am not passing any.

Although, I think I know what the problem is now.

Thanks for your help anyway.  

Chris Hare
chare at labr.net
http://www.labr.net

On Nov 3, 2011, at 9:08 AM, Peter Otten wrote:

> 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...
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111103/3cd059dd/attachment-0001.html>


More information about the Tutor mailing list