TKinter Button widget

tony clarke a.clarke11 at ntlworld.com
Sat Apr 20 14:38:34 EDT 2002


Hi

Yes, there is a way out: defining the function outside the button
definition. This unfortunately can require careful workarounds when the
function is detailed, eg with specific arguments, but unfortunately that
is what Tkinter asks us to do, this version at least.
tonyclarke(nospam)@www.com

Peter Saffrey wrote:

> When I place some buttons on a frame I don't seem to be allowed to use
> arguments in the function call attached to the button. If I do use
> arguments, or even just empty brackets, the function is called when
> the button is placed, not when the button is clicked on.
>
> Below is some simple code which demonstrates this. Is there a way
> around this problem?
>
> Peter
>
> #!/usr/bin/python
>
> from Tkinter import *
>
> def printNumber(number):
>         print number
>
> win = Frame()
> win.pack()
> Button(win, text='print 3', command=printNumber(3)).pack()
> Button(win, text='print 5', command=printNumber(5)).pack()
>
> win.mainloop()




More information about the Python-list mailing list