
Introduction
In this tutorial, we’ll build a Python Alarm Clock that can be used for everything from waking you up in the morning to notifying you at a specified time. The project will allow users to choose a time for their alarm to sound from a menu and automatically notify them at the appropriate moment. Whether you’re new to Python or have some past expertise, this project is an excellent way to learn more about creating functional applications and put your skills to use in a useful and enjoyable way.
Four key steps to make Python Alarm Clock:
Step 1: Importing the Necessary Libraries
Importing all of the necessary libraries and modules is the initial step in starting the project. The datetime, time, and mixer modules from pygames will produce the alarm and sound effects, while the Tkinter library will be used for the visuals. You must first establish the Tkinter window and import the necessary libraries. As an example, let’s type:
Download The Audio file From here: copyassignment.com
# Importing all the necessary modules
from time import strftime
from tkinter import *
import time
import datetime
from pygame import mixer
Step 2: Creating Tkinter GUI
# Setting the main screen
root = Tk()
root.title("CopyAssignment.com")
root.geometry("265x270")
root.resizable(width=False,height=False)
After all of the modules have been imported, it’s time to start Tkinter and design the program’s graphical user interface. We’ll begin by launching Tkinter and creating a window for the Python Alarm Clock. In this case, we set the window size to 265×270 and the window resizability to false.
Step 3: Create the menus, buttons, and labels for the GUI
Now that the GUI has been established, it is time to begin adding frames, labels, and buttons to the GUI. To begin, we’ll make two essential labels: “Alarm Clock” and “Set Time:”. These labels, which will be centered in the window, will inform users about the software and how to interact with it. Then, we’ll create a widget that uses a StringVar to hold all of the hour values that users may select from. Because the clock operates on a 24-hour basis, the readings will range from 0 to 24.
# Creating and placing all the components of the window
hrs=StringVar()
mins=StringVar()
secs=StringVar()
Label(root, font = ('arial', 16, 'bold'),
text="Set Your Alarm Clock!\n [ Its 24Hrs Clock ]\n").grid(row=1,columnspan=4)
Label(root, font = ('arial', 11, 'bold'),
text="Hour").grid(row=3,column=1)
hrbtn=Entry(root,textvariable=hrs,width=5,
font =('arial', 18, 'bold')).grid(row=4,column=1)
Label(root, font = ('arial', 11, 'bold'),
text="Minute").grid(row=3,column=2)
minbtn=Entry(root,textvariable=mins,width=5,
font = ('arial', 18, 'bold')).grid(row=4,column=2)
Label(root, font = ('arial', 11, 'bold'),
text="Second").grid(row=3,column=3)
secbtn=Entry(root,textvariable=secs,
width=5,font = ('arial', 18, 'bold')).grid(row=4,column=3)
Label(root, font = ('arial', 10, 'bold'),
text="Welcome At The CopyAssignment.com").grid(row=7,columnspan=6)
We’ll also set the default hour value to 0 until the user changes it. We’ll then create two additional widgets, one for minutes and one for seconds. These will also be formatted with Tkinter in the same manner as the hours.
Finally, we’ll add a “set alarm” button with the following code:
setbtn=Button(root,text="Set Timer!",command=setalarm,bg="#D4AC0D",
fg="Black",font = ('arial', 19, 'bold')).grid(row=8,columnspan=4)
timeleft = Label(root,font=('arial', 20, 'bold'))
timeleft.grid()
Step 4: Tuning the alarm Function!
Now that the GUI is finished, it’s time to build the alarm function in Python Alarm Clock. Begin by creating a function named “alarmclock” and then a while statement. This statement will be used to receive input from the hour, minute, and second widgets, and then a sleep command will be used to make the program wait for one second. Where Setalarm Function: It generates an alarm by using the alarmClock method and supplying the alarm time as a parameter (if the user has entered a correct and non-empty time).
def setalarm():
alarmtime=f"{hrs.get()}:{mins.get()}:{secs.get()}"
print(alarmtime)
if(alarmtime!="::"):
alarmclock(alarmtime)
def alarmclock(alarmtime):
while True:
time.sleep(1)
# Getting current time by using .striftime() method of the datetime module's datetime file's now function
time_now=datetime.datetime.now().strftime("%H:%M:%S")
print(time_now)
if time_now==alarmtime:
Wakeup=Label(root, font = ('arial', 13, 'bold'),
text="Wake up!Wake up!Wake up",fg="Black").grid(row=9,columnspan=4)
print("wake up!")
mixer.init()
# Playing a sound when the current time is the same as the alarm time
mixer.music.load(r'loud-alarm-02-46010.mp3')
mixer.music.play()
break
Next, we’ll add a piece of code that compares the computer’s local time to the specified alarm time. The datetime module will be used for this. There are now only a few lines left to code! At this point, we just need an if-statement to verify if the times are the same, as well as a command to run Tkinter. Begin by writing an if-statement that checks to see if the current time is equal to the alarm time. If this is the case, we want to print “wake up time” and play the Python Alarm Clock sound. Finally, we’ll add a command to run the Tkinter code, and we’ll be done! Now that the project is completed,
Complete Source Code of Python Alarm Clock | Tkinter GUI App
# Importing all the necessary modules from time import strftime from tkinter import * import time import datetime from pygame import mixer # Setting the main screen root = Tk() root.title("CopyAssignment.com") root.geometry("265x270") root.resizable(width=False,height=False) def setalarm(): alarmtime=f"{hrs.get()}:{mins.get()}:{secs.get()}" print(alarmtime) if(alarmtime!="::"): alarmclock(alarmtime) def alarmclock(alarmtime): while True: time.sleep(1) # Getting current time by using .striftime() method of the datetime module's datetime file's now function time_now=datetime.datetime.now().strftime("%H:%M:%S") print(time_now) if time_now==alarmtime: Wakeup=Label(root, font = ('arial', 13, 'bold'), text="Wake up!Wake up!Wake up",fg="Black").grid(row=9,columnspan=4) print("wake up!") mixer.init() # Playing a sound when the current time is the same as the alarm time mixer.music.load(r'loud-alarm-02-46010.mp3') mixer.music.play() break # Creating and placing all the components of the window hrs=StringVar() mins=StringVar() secs=StringVar() Label(root, font = ('arial', 16, 'bold'), text="Set Your Alarm Clock!\n [ Its 24Hrs Clock ]\n").grid(row=1,columnspan=4) Label(root, font = ('arial', 11, 'bold'), text="Hour").grid(row=3,column=1) hrbtn=Entry(root,textvariable=hrs,width=5, font =('arial', 18, 'bold')).grid(row=4,column=1) Label(root, font = ('arial', 11, 'bold'), text="Minute").grid(row=3,column=2) minbtn=Entry(root,textvariable=mins,width=5, font = ('arial', 18, 'bold')).grid(row=4,column=2) Label(root, font = ('arial', 11, 'bold'), text="Second").grid(row=3,column=3) secbtn=Entry(root,textvariable=secs, width=5,font = ('arial', 18, 'bold')).grid(row=4,column=3) Label(root, font = ('arial', 10, 'bold'), text="Welcome At The CopyAssignment.com").grid(row=7,columnspan=6) setbtn=Button(root,text="Set Timer!",command=setalarm,bg="#D4AC0D", fg="Black",font = ('arial', 19, 'bold')).grid(row=8,columnspan=4) timeleft = Label(root,font=('arial', 20, 'bold')) timeleft.grid() mainloop()
The output of Python Alarm Clock

The project of Python Alarm Clock is finished! You may now use this alarm clock to notify you of events at specified times or to wake you up after a snooze. Feel free to run your code right now to check how it works. If you get stuck or have problems with your code, Please comment to us below.
Also Read:
- Top 25 Pattern Programs in C++
- Currency Converter in C++
- SQLite | CRUD Operations in Python
- Number Guessing Game in C++
- Image background remover in Python
- C++ Project Structure
- Python | Check if a string is a palindrome or not without Recursion
- Python | Check if a number is an Armstrong Number or not using Recursion
- Python | Check if a number is an Armstrong Number or not without using Recursion
- Python | Shuffle a list using recursion
- Python | Shuffle a list without recursion
- Python | Implementing switch case using functions
- Python function to check whether a number is perfect or not
- Python | Find LCM using function
- Python | Find HCF using function
- Python | Convert the binary number to decimal without using library function
- Python | Create a basic operations calculator(+, -, /, and x), create a separate function for each operation
- Python | Detecting the number of local variables declared in a function
- Python | Making a chain of function decorators (bold italic underline etc)
- Python | Access function inside a function
- Event Management System Project in Python
- ATM machine program in C++
- Python | Create a function with a pass statement
- Python | Function to calculate the square root of a number
- Python | A function that calculates the power of a number
- Python | A function that accepts 2 integers and adds them and returns their sum
- Python | Function that takes a list of integers and returns the last integer
- Python | Return multiple values from a function
- Python function that takes a list and returns a new list with unique elements of the first list
- Python | Generate a random number in the range of 1 to 10 using the function