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

Karim karim.liateni at free.fr
Wed Jan 12 21:23:57 CET 2011


Hello,

Inherit from Frame see below:

from Tkinter import *

class App(Frame):
     def __init__(self, master=None):
         Frame.__init__(self, master)
         self.grid()
         self.createLabel()
         self.createButton()

     def createLabel(self):
         self.label = Tkinter.Label(text="")
         self.label.grid()
         self.update_clock()

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

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

app = App()
app.master.title("Clock Time!")
app.mainloop()

Regards
Karim

On 01/12/2011 08:41 PM, Enih Gilead wrote:
> 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()
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110112/0a973b5f/attachment.html>


More information about the Tutor mailing list