TKinter Button widget

Peter Saffrey theoryboy at my-deja.com
Sat Apr 20 10:34:17 EDT 2002


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