Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import time
- import os
- class GUI:
- def __init__(self):
- self.quitting = False
- self.alarm_state = False
- self.win = Tk()
- self.win.title("Clock")
- self.win.protocol("WM_DELETE_WINDOW", self.quitter) ## runs the function when the X button is pressed.
- def quitter(self): # function controls how the application should close
- self.quitting = True
- def button(self): #Triggers the application to start checking the alarm to see if it has elapsed
- self.alarm_state = True
- def check_alarm(self):
- if self.alarm.get()==time.strftime('%H:%M:%S'):
- print("Times Up!")
- self.alarm_state = False
- def run(self):
- timer = Label(self.win,font=('times', 28, 'bold'), background='blue', foreground='white') ##renamed this to be easier to read
- timer.pack(fill=BOTH, expand=1)
- self.alarm=Entry(self.win)
- self.alarm.pack()
- bt=Button(self.win, text='Set alarm', command=self.button).pack()
- while not self.quitting:
- self.win.update()
- self.win.update_idletasks()
- timer["text"] = time.strftime('%H:%M:%S')
- if self.alarm_state:
- self.check_alarm()
- if __name__ == "__main__":
- app= GUI() ##creates the app as an object
- try:
- app.run() ##runs the application
- except KeyboardInterrupt:
- app.quitter() ##safly quits the application if ctrl+c is pressed
- except:
- raise ##displays any other errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement