what's the difference between mainloop and app.mainloop and root.mainloop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luofeiyu
    New Member
    • Jul 2011
    • 18

    what's the difference between mainloop and app.mainloop and root.mainloop?

    Code:
    #code1
    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()
    Code:
    #code2
    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") 
    root=Tk()
    root.mainloop()
    Code:
    #code3
    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") 
    mainloop()

    what's the difference between mainloop and app.mainloop and root.mainloop?
    do they have different meaning?
    which one is right or the best in code1,code2,cod e3??
Working...