[Tkinter-discuss] How to make Button Command work as a called function ?

bogzab bogus at bogzab.plus.com
Mon Nov 2 22:48:53 CET 2009

I think I am making a rookie error with this somewhere but cannot figure out

If I create a button with these lines of code :

	topwin = Tk()
	frame = Frame(topwin)
	butt2 = Button(frame, text="Not yet", command=topwin.iconfiy)

When the program runs, the button acts as expected and the window is

If however the line which creates the button is :

	butt2 = Button(frame, text="Not yet", command=wait_a_bit)

where wait_a_bit is a function I define as follows :

	def wait_a_bit():
		print "Pressed No"

then the print statement in this function works, but the topwin.iconify
does not.

I have tried declaring topwin to be global but this made no difference.

Can anybody point me to where my error lies in the second approach ? I want
do it as a function because there are other bits of code as well as the
that I need to incorporate.

View this message in context: http://old.nabble.com/How-to-make-Button-Command-work-as-a-called-function---tp26157859p26157859.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.

More information about the Tkinter-discuss mailing list