Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from alarm import alarm_gui
- from aceutil import TkUtils, Log #download from https://pastebin.com/yUaMxmv3
- from tkutils import * #download from https://pastebin.com/TLdsJ2er
- class TKGUI:
- def __init__(self):
- self.root= Tk() ##initilise the main window
- self.quit = False ##defaults the quit flag
- self.log = Log("Alarm Clock")
- self.tku = TkUtils(self.log, self.root)
- self.alarm = alarm_gui(self.root, self.log, self.tku)
- 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")
- self.tku.cButton(self.root, text="open alarm", command=lambda e=Event():self.open_alarm_gui(e))
- #############################################################
- #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
- #----------------------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.
- self.alarm.update_clock()
- if self.alarm.trigger_alarms():
- self.alarm_has_been_triggered()
- #add extra functions here if you need them to run with the loop#
- def alarm_has_been_triggered(self):
- print("main.py has detected an alarm being triggerd")
- def open_alarm_gui(self, event):
- self.alarm_holder = Toplevel()
- self.alarm_holder.protocol("WM_DELETE_WINDOW", self.quitting_alarm)
- self.alarm.main_window(self.alarm_holder)
- def quitting_alarm(self):
- self.alarm.quitting()
- self.alarm_holder.destroy()
- 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