[Tutor] how to call a binding method from an imported module

Rich Lovely roadierich at googlemail.com
Sat Nov 1 01:03:49 CET 2008


Is TempDef defined within a class block? All functions defined within  
a class take self as the first (or only) argument. That appears to be  
the usual cause of that error... Otherwise, you can say
def tempDef(*args):
     #stuff

Or just
def tempDef(args):
     #stuff

Seeing as it only receives one arguement.

---
Richard "Roadie Rich" Lovely
Part of the JNP|UK Famille
www.theJNP.com
---
(Sent from my iPod - please allow for any typos: it's a very small  
keyboard)

On 31 Oct 2008, at 20:16, dwbarne at earthlink.net wrote:

> This problem involves a callback method while using 'bind'. The bind  
> statement and the callback function are both in a module imported to  
> the main program. Relevant code snippets are as follows:
>
> #++++ begin snippet
>
> # main code
> <code>
> import module_Editor
> .
> class MyClass():
> <code>
>    def editor(self):
>
>        module_Editor.my_Editor(self,self.frameParent)
> <code>
> # end of main code
>
> # module 'module_Editor'
> <imports>
> def my_Editor(self,parentFrame):
> <code>
>    self.textMyCode.bind(
>        "<KeyPress-Return>",
>        handlerTextLineNumbersReturn(self)
>        )
> <code>
> def handlerTextLineNumbersReturn(self,event):
>    def temp():
>
>        print '\n** In handlerTextLineNumbersReturn'
>
>    return temp
> <code>
> # end of module 'module_Editor'
>
> # ++++ end snippet
>
> When the bind callback handler is called, the following error is  
> returned:
>
> ++++ begin error
> Exception in Tkinter callback
> Traceback (most recent call last):
> File "c:\Python251_102507\lib\lib-tk\Tkinter.py", line 1403, in  
> __call__
>    return self.func(*args)
> TypeError: tempDef() takes no arguments (1 given)
>
> ++++ end error
>
> The above approach works for widgets in the module calling callback  
> handlers that return a def like the above, but bind statements  
> apparently do not like this approach for some reason.
>
> Any ideas on what I'm doing wrong here? Maybe a "*args" needs to go  
> somewhere in the calling or def statements? If so, where does it go?
>
> Daniel
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list