Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from aceutil import TkUtils, Log
- class TKGUI:
- def __init__(self):
- self.appname = "Tester"
- self.root= Tk() ##initilise the main window
- self.log = Log(self.appname)
- self.tku = TkUtils(self.log, self.root)
- self.quit = False ##defaults the quit flag
- def test_movable_window(self, event):
- over = self.tku.overlay(self.root, Event(), "Drag to Move", height=400, width=400) # Creates the Movable window
- window = self.tku.cFrame(over, padx=5, pady=5, fill=BOTH, expand=1) #Pads the window to prevent overflow
- #content, canvas = self.tku.scrollable_area2(window) ##Adds a scrollable area. This is a bit bugged atm
- for i in range(10):
- Label(window, text="This is a Test: %s"%i, bg="white").pack(side=TOP)
- 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(self.appname)
- self.root.geometry("800x600")
- self.tku.cButton(self.root, text="Open Window", fg="black", bg="white", command=lambda e=Event():self.test_movable_window(e))
- 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
Add Comment
Please, Sign In to add comment