Alarm clock GUI application with tkinter


Hope you are doing great!

Today, We are going to see how can we create a Alarm clock GUI application with tkinter. Choose the time and choose your favorite melody to start the day with pleasure, and not to oversleep interesting moments.

For this, we need the tkinter module and playsound module.

Playsound is a Pure Python, cross platform, single function module with no dependencies for playing sounds.

Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy way to create GUI applications.

To install tkinter module python, type the below command in your terminal–

pip install tkinter

To install playsound module python, type the below command in your terminal–

pip install playsound

So, Here is the source code for Alarm clock GUI application with tkinter

Source Code With Comments

from tkinter import * from tkinter import messagebox import datetime, time # just import from playsound import playsound # pip install playsound # change color of button when cursor on it def button_hover(event): confirm["bg"] = "lightblue" # change color of button when remove cursor from it def button_hover_leave(event): confirm["bg"] = "SystemButtonFace" # check time with alarm time, and turn ON alarm def alarm(set_alarm): while True: current = date = current.strftime("%d.%m.%Y") time_atm = current.strftime("%H:%M:%S") if time_atm == set_alarm: print("Alarmaaaa") # in my case .mp3 file is in same folder playsound("alarm.mp3") break # recive data from user(spinbox) def alarm_time(): h = hour.get() m = minutes.get() answer = messagebox.showinfo("Set alarm", f"Alarm will signal at\n{h}:{m}") set_alarm = f"{h}:{m}:00" alarm(set_alarm) if __name__ == "__main__": window = Tk() window.geometry("400x210") window.title("Alarm") choose_time = Label(text="Choose the alarm time"), y=20) hour = IntVar() Spinbox(width=4, from_=0, to=23, state="readonly", textvariable=hour, wrap=True).place(x=200, y=20) minutes = IntVar() Spinbox(width=4, from_=0, to=59, state="readonly", textvariable=minutes, wrap=True).place(x=240, y=20) confirm = Button(text="Set alarm", command=alarm_time, width=10, height=3), y=70) confirm.bind("<Enter>", button_hover) confirm.bind("<Leave>", button_hover_leave) exit = Button(text="Quit",width=10, command=window.destroy), y=170) made_by = Label(text="TECHARGE").place(x = 300, y = 178) window.mainloop()
Code language: Python (python)


alarm clock with gui using python
alarm clock with gui using python

So, here is Alarm clock GUI application with tkinter using Python. Simple isn’t it?? This is how we have successfully done with the ‘text to Speech using Python’. I hope the ‘Tkinter and Playsound library is now more clear to you and don’t forget to try this code once!!

You can play around with the library, explore more features and even customize it further and Don’t forget to share with your friends.

ThankYou Pythoner’s!!! 🙂

Check out more python projects

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Enable Notifications    OK No thanks