Stewart Midwinter wrote:
> The problem with your test app is that in your button definition, you
> didn't just provide the name of a method for the callback,you also
> provided an argument for it. That ensures that the callback will be
> called as soon as the button is instantiated.
>
> To get around this, one approach is to use a lambda function. Another
> approach is to create a separate function for each button and call it
> without any arguments. Here are the final lines of your test app with
> the 2nd approach:
<snip>
Thanks for the reply. I thought it was probably something like that with
the tests I've done. I was reading a book that said I could do it, but
it's a bit old (for Python 2.1). I only really use it for a reference.
So I've implemented what I wanted through lambda, which works perfectly
well. Thanks for your help!
-M.
-------------------------------------------------------------------------------------
# ...
self.button7 = Button (self.topbuttonframe, text = "7", width =
2, command = lambda y = '7' : self.buttonAction(y))
# ...
def buttonAction (self, action = '+'):
self.entry["state"] = NORMAL
self.entry.insert (self.place, action)
self.place = self.place + 1
self.entry["state"] = DISABLED
# ...
-------------------------------------------------------------------------------------
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss