Repository navigation
Expand file tree
/
Copy pathAlarm-Clock.py
More file actions
59 lines (49 loc) · 1.74 KB
/
Copy pathAlarm-Clock.py
File metadata and controls
59 lines (49 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Importing all the necessary libraries to form the alarm clock:
import datetime
import time
import winsound
from tkinter import *
def alarm(set_alarm_timer):
while True:
time.sleep(1)
current_time = datetime.datetime.now()
now = current_time.strftime("%H:%M:%S")
date = current_time.strftime("%d/%m/%Y")
print("The Set Date is:", date)
print(now)
if now == set_alarm_timer:
print("Time to Wake up")
winsound.PlaySound("sound.wav", winsound.SND_ASYNC)
break
def actual_time():
set_alarm_timer = f"{hour.get()}:{min.get()}:{sec.get()}"
alarm(set_alarm_timer)
clock = Tk()
clock.title("DataFlair Alarm Clock")
clock.iconbitmap(r"dataflair-logo.ico")
clock.geometry("400x200")
time_format = Label(
clock, text="Enter time in 24 hour format!", fg="red", bg="black", font="Arial"
).place(x=60, y=120)
addTime = Label(clock, text="Hour Min Sec", font=60).place(x=110)
setYourAlarm = Label(
clock,
text="When to wake you up",
fg="blue",
relief="solid",
font=("Helevetica", 7, "bold"),
).place(x=0, y=29)
# The Variables we require to set the alarm(initialization):
hour = StringVar()
min = StringVar()
sec = StringVar()
# Time required to set the alarm clock:
hourTime = Entry(clock, textvariable=hour, bg="pink", width=15).place(x=110, y=30)
minTime = Entry(clock, textvariable=min, bg="pink", width=15).place(x=150, y=30)
secTime = Entry(clock, textvariable=sec, bg="pink", width=15).place(x=200, y=30)
# To take the time input by user:
submit = Button(clock, text="Set Alarm", fg="red", width=10, command=actual_time).place(
x=110, y=70
)
clock.mainloop()
# Execution of the window.