AceScottie

freecode.py

Aug 20th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. from tkinter import *
  2. from aceutil import TkUtils, Log
  3.  
  4. class TKGUI:
  5.     def __init__(self):
  6.         self.appname = "Tester"
  7.         self.root= Tk() ##initilise the main window
  8.         self.log = Log(self.appname)
  9.         self.tku = TkUtils(self.log, self.root)
  10.         self.quit = False ##defaults the quit flag
  11.  
  12.     def test_movable_window(self, event):
  13.         over = self.tku.overlay(self.root, Event(), "Drag to Move", height=400, width=400) # Creates the Movable window
  14.         window = self.tku.cFrame(over, padx=5, pady=5, fill=BOTH, expand=1) #Pads the window to prevent overflow
  15.         #content, canvas = self.tku.scrollable_area2(window) ##Adds a scrollable area. This is a bit bugged atm
  16.        
  17.         for i in range(10):
  18.             Label(window, text="This is a Test: %s"%i, bg="white").pack(side=TOP)
  19.  
  20.     def run(self): ##main part of the application
  21.         self.root.configure(bg="white") #sets the background to white rather than default gray.
  22.         self.root.protocol("WM_DELETE_WINDOW", self.quitting) ##changes the X (close) Button to run a function instead.
  23.         try:
  24.             self.root.iconbitmap("fav.ico") ##sets the application Icon
  25.         except:
  26.             pass
  27.         self.root.title(self.appname)
  28.         self.root.geometry("800x600")
  29.         self.tku.cButton(self.root, text="Open Window", fg="black", bg="white", command=lambda e=Event():self.test_movable_window(e))
  30.         while not self.quit: ##flag to quit the application
  31.             self.root.update_idletasks() #updates the root. same as root.mainloop() but safer and interruptable
  32.             self.root.update() #same as above. This lest you stop the loop or add things to the loop.
  33.             #add extra functions here if you need them to run with the loop#
  34.  
  35.     def quitting(self): ##to set the quit flag
  36.         self.quit = True
  37.            
  38. if __name__ == "__main__":
  39.     app = TKGUI() ##creates instance of GUI class
  40.     try:
  41.         app.run()# starts the application
  42.     except KeyboardInterrupt:
  43.         app.quitting() ##safely quits the application when crtl+C is pressed
  44.     except:
  45.         raise #you can change this to be your own error handler if needed
Add Comment
Please, Sign In to add comment