0% found this document useful (0 votes)
40 views

Python Project On Alarm

This document summarizes the code for creating an alarm clock application using Tkinter in Python. It imports necessary libraries, creates a while loop to check the current time against the set alarm time, and plays a sound file if they match. It then defines functions for setting the alarm and getting the actual time. Finally, it creates a GUI using Tkinter to allow the user to enter the hour, minute and second for the alarm time and set the alarm by clicking a button. Running the Python file executes the alarm clock application.

Uploaded by

Lohith M
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Python Project On Alarm

This document summarizes the code for creating an alarm clock application using Tkinter in Python. It imports necessary libraries, creates a while loop to check the current time against the set alarm time, and plays a sound file if they match. It then defines functions for setting the alarm and getting the actual time. Finally, it creates a GUI using Tkinter to allow the user to enter the hour, minute and second for the alarm time and set the alarm by clicking a button. Running the Python file executes the alarm clock application.

Uploaded by

Lohith M
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

First, we import all the necessary libraries and modules:

#Importing all the necessary libraries to form the alarm clock:


from tkinter import *
import datetime
import time
import winsound

Create a while loop:

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)

Creating GUI using tkinter:

clock = Tk()
clock.title("DataFlair Alarm Clock")
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.

Yay!! The alarm clock is ready for execution for your next work nap 😉. Save the
source code with DataFlair-Alarm-Clock.py and run the file:

python3 DataFlair-Alarm-Clock.py

You might also like