[Tutor] How to insert a quit-Button in a Tkinter class?

Enih Gilead egilead at gmail.com
Wed Jan 12 20:41:25 CET 2011


Hi, all !

I've being strugling a lot trying to insert (just as exemple) a 
quit-Button in a Tkinter class App with no success...  What I get is the 
clock runing ok, but, the App simply ignores the quit-Button...  Why?

_*Remark*_:
I took this minimalist digital clock just to illustrate the "bad  :-)" 
class behavior, but it didn't work in any other Apps I tried.  I 
searched a lot (indeed!) in the net but I couldn't find the reason.

Could any of you tell me, please, _*what's the problem?*_
Thanks,
enihgil

###################################

import Tkinter
import time

class App():
     def __init__(self):
         self.root = Tkinter.Tk()
         self.label = Tkinter.Label(text="")
         self.label.grid()
         self.update_clock()
         self.root.mainloop()

     def update_clock(self):
         now = time.strftime("%H:%M:%S")
         self.label.configure(text=now)
         self.root.after(1000, self.update_clock)

     def createButton(self):
         self.quitButton = Button( self, text='Quit', command=self.quit )
         self.quitButton.grid()

app=App()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110112/c88d374c/attachment.html>


More information about the Tutor mailing list