Skip to content

Commit 7a24b7a

Browse files
authored
Add files via upload
1 parent 0474815 commit 7a24b7a

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

Alarm clock/alarm_clock.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Import Required Library
2+
from tkinter import *
3+
import datetime
4+
import time
5+
import winsound
6+
from threading import *
7+
8+
# Create Object
9+
root = Tk()
10+
11+
# Set geometry
12+
root.geometry("400x200")
13+
14+
# Use Threading
15+
def Threading():
16+
t1=Thread(target=alarm)
17+
t1.start()
18+
19+
def alarm():
20+
# Infinite Loop
21+
while True:
22+
# Set Alarm
23+
set_alarm_time = f"{hour.get()}:{minute.get()}:{second.get()}"
24+
25+
# Wait for one seconds
26+
time.sleep(1)
27+
28+
# Get current time
29+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
30+
print(current_time,set_alarm_time)
31+
32+
# Check whether set alarm is equal to current time or not
33+
if current_time == set_alarm_time:
34+
print("Time to Wake up")
35+
# Playing sound
36+
winsound.PlaySound("sound.wav",winsound.SND_ASYNC)
37+
38+
# Add Labels, Frame, Button, Optionmenus
39+
Label(root,text="Alarm Clock",font=("Helvetica 20 bold"),fg="red").pack(pady=10)
40+
Label(root,text="Set Time",font=("Helvetica 15 bold")).pack()
41+
42+
frame = Frame(root)
43+
frame.pack()
44+
45+
hour = StringVar(root)
46+
hours = ('00', '01', '02', '03', '04', '05', '06', '07',
47+
'08', '09', '10', '11', '12', '13', '14', '15',
48+
'16', '17', '18', '19', '20', '21', '22', '23', '24'
49+
)
50+
hour.set(hours[0])
51+
52+
hrs = OptionMenu(frame, hour, *hours)
53+
hrs.pack(side=LEFT)
54+
55+
minute = StringVar(root)
56+
minutes = ('00', '01', '02', '03', '04', '05', '06', '07',
57+
'08', '09', '10', '11', '12', '13', '14', '15',
58+
'16', '17', '18', '19', '20', '21', '22', '23',
59+
'24', '25', '26', '27', '28', '29', '30', '31',
60+
'32', '33', '34', '35', '36', '37', '38', '39',
61+
'40', '41', '42', '43', '44', '45', '46', '47',
62+
'48', '49', '50', '51', '52', '53', '54', '55',
63+
'56', '57', '58', '59', '60')
64+
minute.set(minutes[0])
65+
66+
mins = OptionMenu(frame, minute, *minutes)
67+
mins.pack(side=LEFT)
68+
69+
second = StringVar(root)
70+
seconds = ('00', '01', '02', '03', '04', '05', '06', '07',
71+
'08', '09', '10', '11', '12', '13', '14', '15',
72+
'16', '17', '18', '19', '20', '21', '22', '23',
73+
'24', '25', '26', '27', '28', '29', '30', '31',
74+
'32', '33', '34', '35', '36', '37', '38', '39',
75+
'40', '41', '42', '43', '44', '45', '46', '47',
76+
'48', '49', '50', '51', '52', '53', '54', '55',
77+
'56', '57', '58', '59', '60')
78+
second.set(seconds[0])
79+
80+
secs = OptionMenu(frame, second, *seconds)
81+
secs.pack(side=LEFT)
82+
83+
Button(root,text="Set Alarm",font=("Helvetica 15"),command=Threading).pack(pady=20)
84+
85+
# Execute Tkinter
86+
root.mainloop()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy