Advertisement
AceScottie

alarm_clock.py

Jan 8th, 2020
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. from tkinter import *
  2. import time
  3. import os
  4.  
  5. quitting = False
  6. alarm_state = False
  7.  
  8. def quitter(): # function controls how the application should close
  9.     global quitting
  10.     quitting = True
  11.  
  12. win = Tk()
  13. win.title("Clock")
  14. win.protocol("WM_DELETE_WINDOW", quitter) ## runs the function when the X button is pressed.
  15.  
  16. example = Label(win,font=('times', 28, 'bold'), background='blue', foreground='white')
  17. example.pack(fill=BOTH, expand=1)
  18. e1=Entry(win)
  19. e1.pack()
  20.  
  21. def button():
  22.     global alarm_state
  23.     alarm_state = True
  24.        
  25. bt=Button(win, text='Set alarm', command=button).pack()
  26.  
  27. def check_alarm(settime):
  28.     global alarm_state
  29.     if settime.get()==time.strftime('%H:%M:%S') and alarm_state:
  30.         print("Times Up!")
  31.         alarm_state = False
  32.  
  33. while not quitting:
  34.     win.update()
  35.     win.update_idletasks()
  36.     example["text"]  = time.strftime('%H:%M:%S')
  37.     check_alarm(e1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement