Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- class TKGUI:
- def __init__(self):
- self.root= Tk() ##initilise the main window
- self.quit = False ##defaults the quit flag
- def run(self): ##main part of the application
- self.root.configure(bg="white") #sets the background to white rather than default gray.
- self.root.protocol("WM_DELETE_WINDOW", self.quitting) ##changes the X (close) Button to run a function instead.
- try:
- self.root.iconbitmap("fav.ico") ##sets the application Icon
- except:
- pass
- self.root.title("MyApp")
- self.root.geometry("800x600")
- #############################################################
- #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
- #----------------------Code Goes Here ----------------------#
- #///////////////////////////////////////////////////////////#
- #############################################################
- #############################################################
- while not self.quit: ##flag to quit the application
- self.root.update_idletasks() #updates the root. same as root.mainloop() but safer and interruptable
- self.root.update() #same as above. This lest you stop the loop or add things to the loop.
- #add extra functions here if you need them to run with the loop#
- def quitting(self): ##to set the quit flag
- self.quit = True
- if __name__ == "__main__":
- app = TKGUI() ##creates instance of GUI class
- try:
- app.run()# starts the application
- except KeyboardInterrupt:
- app.quitting() ##safely quits the application when crtl+C is pressed
- except:
- raise #you can change this to be your own error handler if needed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement