As we all know, nowadays wake up on time is a very difficult task. The solution is the Alarm Clock. In this article, we will learn, How to create an Alarm Clock using Tkinter in Python. Without alarms, several people would oversleep and land up late for work. Alarm clocks may also be useful for keeping sleep schedules regular.
- Tkinter: Python offers multiple choices for developing a GUI (Graphical User Interface). Out of all the GUI strategies, tkinter is that the most ordinarily used technique. It’s a customary Python interface to the Tk GUI toolkit shipped with Python.
- Winsound: The winsound module provides access to the essential sound-playing machinery provided by Windows platforms. It includes functions and a number of other constants. Beep the PC’s speaker.
- time: Time module in Python provides varied time-related functions. This module comes with Python’s normal modules.
- datetime: The main focus of datetime is to form it simpler to access attributes of the thing associated with dates, times, and time zones.
Below is what GUI looks like:-
Let’s Understand step by step implementation:
Step1: Import Required Library
Step 2: Add Button, Labels, Frame, and option menus
Button(Object Name, text=”Enter Text”,**attr)
Label(Object Name, text=”Enter Text”, command=”Enter Command” , **attr)
Frame(Object Name, **attr)
# Option Menu
OptionMenu(“Object Name”, “Data Type”, “list of value in form of tuple”, **attr)
We will create a three-option menu:-
- Hours (00–24)
- Minutes (00–60)
- Seconds (00–60)
Time is in 24-hour time format.
Step 3: Make a function named alarm(), which performs alarm clock work.
Below is the full implementation:
- Make Infinite Loop
- Get hours, minutes, seconds value from the user
- Wait for one second using time module
- Get Current time using datetime module
- Check if the current time is equal to set time; play sound using winsound module
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.