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

Enih Gilead egilead at gmail.com
Thu Jan 13 18:24:41 CET 2011


Hi All !
Thanks a lot for the great help.  As a beginner, I was forgetting to see 
the "Inheritance from Frame", but now it's all runing ok.
Thankfull,
enihgil

On 01/12/2011 06:23 PM, Karim wrote:
>
> 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
>
>
> _______________________________________________
> 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/20110113/78f7f026/attachment-0001.html>


More information about the Tutor mailing list