TKinter Button widget

Peter Saffrey theoryboy at my-deja.com
Sun Apr 21 10:43:54 EDT 2002


Perhaps I should have said that I need this in an object-oriented
context. It doesn't seem to work using an anonymous lambda function to
a class method: example below.

Sorry, I didn't realise it would make any difference, and I was trying
to make my example concise.

Peter

#!/usr/bin/python

from Tkinter import *

class gui:
	def __init__(self):
		win = Frame()
		win.pack()
		Button(win, text='print 3',
command=lambda:self.printNumber(3)).pack()
		Button(win, text='print 5',
command=lambda:self.printNumber(5)).pack()

		win.mainloop()
		
	def printNumber(number):
	        print number
        
if __name__ == '__main__':
	test = gui()



More information about the Python-list mailing list