Advertisement
AceScottie

Tkinter_base.py

Nov 28th, 2018
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. from Tkinter import *
  2.  
  3. class TKGUI:
  4.     def __init__(self):
  5.         self.root= Tk() ##initilise the main window
  6.         self.quit = False ##defaults the quit flag
  7.        
  8.  
  9.     def run(self): ##main part of the application
  10.         self.root.configure(bg="white") #sets the background to white rather than default gray.
  11.         self.root.protocol("WM_DELETE_WINDOW", self.quitting) ##changes the X (close) Button to run a function instead.
  12.         try:
  13.             self.root.iconbitmap("fav.ico") ##sets the application Icon
  14.         except:
  15.             pass
  16.         self.root.title("MyApp")
  17.         self.root.geometry("800x600")
  18.         #############################################################
  19.         #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
  20.         #----------------------Code Goes Here ----------------------#
  21.         #///////////////////////////////////////////////////////////#
  22.         #############################################################
  23.        
  24.        
  25.        
  26.         #############################################################
  27.         while not self.quit: ##flag to quit the application
  28.             self.root.update_idletasks() #updates the root. same as root.mainloop() but safer and interruptable
  29.             self.root.update() #same as above. This lest you stop the loop or add things to the loop.
  30.             #add extra functions here if you need them to run with the loop#
  31.  
  32.     def quitting(self): ##to set the quit flag
  33.         self.quit = True
  34.            
  35. if __name__ == "__main__":
  36.     app = TKGUI() ##creates instance of GUI class
  37.     try:
  38.         app.run()# starts the application
  39.     except KeyboardInterrupt:
  40.         app.quitting() ##safely quits the application when crtl+C is pressed
  41.     except:
  42.         raise #you can change this to be your own error handler if needed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement