Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import datetime as dt
- import playsound as ps
- def checkTime(hr, mn):
- chr = dt.datetime.now().hour
- cmn = dt.datetime.now().minute
- if chr == hr and cmn == mn:
- print("Alarm going off!")
- ps.playsound("alarm.mp3", block=False)
- else:
- window.after(1000, lambda: checkTime(hr, mn))
- def setAlarm():
- hr = ent_hr.get()
- mn = ent_min.get()
- print(f"Alarm set for {hr}:{mn}.")
- checkTime(int(hr), int(mn))
- window = tk.Tk()
- window.title("Alarm Clock")
- lbl_hr = tk.Label(text = "Hour: ")
- lbl_min = tk.Label(text = "Minute: ")
- ent_hr = tk.Entry()
- ent_min = tk.Entry()
- btn_set = tk.Button(text="Set Alarm", command=setAlarm)
- lbl_hr.grid(row = 0, column = 0, padx=(30, 2), pady=(15, 2))
- lbl_min.grid(row = 1, column = 0, padx=(30, 2), pady=(2, 30))
- ent_hr.grid(row = 0, column = 1, padx = (2, 30), pady=(15,2))
- ent_min.grid(row = 1, column = 1, padx=(2, 30), pady=(2, 5))
- btn_set.grid(row = 2, column = 0, columnspan = 2, pady=(0, 15))
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement