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

dwbarne at earthlink.net dwbarne at earthlink.net
Fri Oct 31 21:16:52 CET 2008


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


More information about the Tutor mailing list