Is it necessary to call Tk() when writing a GUI app with Tkinter?

John Salerno johnjsal at gmail.com
Thu Mar 1 01:41:53 EST 2012


> Yes. You must leave it out.

Now I'm reading a Tkinter reference at
http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html
and it has this example:


#!/usr/local/bin/python     
from Tkinter import *       

class Application(Frame):              
    def __init__(self, master=None):
        Frame.__init__(self, master)   
        self.grid()                    
        self.createWidgets()

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

app = Application()                    
app.master.title("Sample application") 
app.mainloop()


Is this just outdated? I don't understand why it uses quit() instead of destroy(). When I try this in IDLE, quit() just causes the application to hang (I assume because it ends the mainloop without actually closing the application). Or is this just a problem when using IDLE?

If the latter, which is preferable, quit or destroy?



More information about the Python-list mailing list