By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,403 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,403 IT Pros & Developers. It's quick & easy.

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

P: 18
Expand|Select|Wrap|Line Numbers
  1. #code1
  2. from Tkinter import *       
  3. class Application(Frame):     
  4.     def __init__(self, master=None):
  5.         Frame.__init__(self, master)   
  6.         self.grid()                    
  7.         self.createWidgets()
  8.  
  9.     def createWidgets(self):
  10.         self.quitButton = Button ( self, text='Quit',
  11.             command=self.quit )               
  12.         self.quitButton.grid()         
  13.  
  14. app = Application()
  15. app.master.title("Sample application") 
  16. app.mainloop()
  17.  
Expand|Select|Wrap|Line Numbers
  1. #code2
  2. from Tkinter import *       
  3. class Application(Frame):     
  4.     def __init__(self, master=None):
  5.         Frame.__init__(self, master)   
  6.         self.grid()                    
  7.         self.createWidgets()
  8.  
  9.     def createWidgets(self):
  10.         self.quitButton = Button ( self, text='Quit',
  11.             command=self.quit )               
  12.         self.quitButton.grid()         
  13.  
  14. app = Application()
  15. app.master.title("Sample application") 
  16. root=Tk()
  17. root.mainloop()
  18.  
Expand|Select|Wrap|Line Numbers
  1. #code3
  2. from Tkinter import *       
  3. class Application(Frame):     
  4.     def __init__(self, master=None):
  5.         Frame.__init__(self, master)   
  6.         self.grid()                    
  7.         self.createWidgets()
  8.  
  9.     def createWidgets(self):
  10.         self.quitButton = Button ( self, text='Quit',
  11.             command=self.quit )               
  12.         self.quitButton.grid()         
  13.  
  14. app = Application()
  15. app.master.title("Sample application") 
  16. mainloop()
  17.  

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,code3??
Aug 24 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.