Advertisement
AceScottie

main.py

Jan 18th, 2020
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. from tkinter import *
  2. from alarm import alarm_gui
  3. from aceutil import TkUtils, Log #download from https://pastebin.com/yUaMxmv3
  4. from tkutils import * #download from https://pastebin.com/TLdsJ2er
  5.  
  6. class TKGUI:
  7.     def __init__(self):
  8.         self.root= Tk() ##initilise the main window
  9.         self.quit = False ##defaults the quit flag
  10.         self.log = Log("Alarm Clock")
  11.         self.tku = TkUtils(self.log, self.root)
  12.         self.alarm = alarm_gui(self.root, self.log, self.tku)
  13.  
  14.     def run(self): ##main part of the application
  15.         self.root.configure(bg="white") #sets the background to white rather than default gray.
  16.         self.root.protocol("WM_DELETE_WINDOW", self.quitting) ##changes the X (close) Button to run a function instead.
  17.         try:
  18.             self.root.iconbitmap("fav.ico") ##sets the application Icon
  19.         except:
  20.             pass
  21.         self.root.title("MyApp")
  22.         self.root.geometry("800x600")
  23.         self.tku.cButton(self.root, text="open alarm", command=lambda e=Event():self.open_alarm_gui(e))
  24.         #############################################################
  25.         #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
  26.         #----------------------Code Goes Here ----------------------#
  27.         #///////////////////////////////////////////////////////////#
  28.         #############################################################
  29.        
  30.        
  31.        
  32.         #############################################################
  33.         while not self.quit: ##flag to quit the application
  34.             self.root.update_idletasks() #updates the root. same as root.mainloop() but safer and interruptable
  35.             self.root.update() #same as above. This lest you stop the loop or add things to the loop.
  36.             self.alarm.update_clock()
  37.             if self.alarm.trigger_alarms():
  38.                 self.alarm_has_been_triggered()
  39.             #add extra functions here if you need them to run with the loop#
  40.            
  41.     def alarm_has_been_triggered(self):
  42.         print("main.py has detected an alarm being triggerd")
  43.    
  44.     def open_alarm_gui(self, event):
  45.         self.alarm_holder = Toplevel()
  46.         self.alarm_holder.protocol("WM_DELETE_WINDOW", self.quitting_alarm)
  47.         self.alarm.main_window(self.alarm_holder)
  48.  
  49.     def quitting_alarm(self):
  50.         self.alarm.quitting()
  51.         self.alarm_holder.destroy()
  52.     def quitting(self): ##to set the quit flag
  53.         self.quit = True
  54.            
  55. if __name__ == "__main__":
  56.     app = TKGUI() ##creates instance of GUI class
  57.     try:
  58.         app.run()# starts the application
  59.     except KeyboardInterrupt:
  60.         app.quitting() ##safely quits the application when crtl+C is pressed
  61.     except:
  62.         raise #you can change this to be your own error handler if needed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement