FW: Need help with Tkinter bind statement

Mellor, Mike Mike.mellor at tbe.com
Tue Mar 6 21:22:49 CET 2001


-----Original Message-----
From: Mellor, Mike 
Sent: Tuesday, March 06, 2001 2:41 PM
To: python-list at yahoogroups.com
Subject: Need help with Tkinter bind statement


Hello - 
I have been working on an RPN calculator program for a while now, and 
I am having problems with some bindings.  Here is a code snippet of 
where I'm having trouble:

# Bindings
xStack.bind('<+>', lambda event, fxn = 'y+x':Calc(fxn))
xStack.bind('<->', lambda event, fxn = 'y-x':Calc(fxn)) # This is 
causing an error
xStack.bind('<*>', lambda event, fxn = 'y*x':Calc(fxn))
xStack.bind('</>', lambda event, fxn = 'y/x':Calc(fxn))

where xStack is an entry widget and Calc is a function that does the 
calculation.  

My 1st problem is that binding to the "-" key generates this error:

Traceback (most recent call last):
  File "D:\Python21\Projects\MCalc7.py", line 98, in ?
    xStack.bind('<->', lambda event, fxn = 'y-x':Calc(fxn)) # This is 
causing an error
  File "d:\python21\lib\lib-tk\Tkinter.py", line 899, in bind
    return self._bind(('bind', self._w), sequence, func, add)
  File "d:\python21\lib\lib-tk\Tkinter.py", line 854, in _bind
    self.tk.call(what + (sequence, cmd))
TclError: no event type or button # or keysym

but the other bindings work fine.  The second problem is that when I 
use any of these keys, the keystroke shows up in the entry widget.  
What I want to happen is that pressing the "+" key, for example, 
should add the values in the xStack and yStack (which it does) and 
then put the result in the yStack entry widget (which it also does).  
The problem is that the "+" is left in the xStack.  The contents of 
the xStack are deleted by the Calc function, so I thought it would 
also delete the "+" as well.  

Thanks.

Mike








More information about the Python-list mailing list