This project is designed to implement an alarm clock using Tkinter in Python. Which rings after a certain time has been set to it.
These initial lines of code are designed to take input from the user.
That is, which time the user wants to set the alarm for.
def createWidgets(): label1=Label(root, text="Enter the time in hh:mm:", borderwidth=2, relief="solid") label1.grid(row=0, column=0, padx=5, pady=5) global entry1 entry1= Entry(root, width=15) entry1.grid(row=0, column=1) label2=Label(root, text="enter the message of alarm", borderwidth=2, relief="solid") label2.grid(row=1, column=0, padx=5, pady=5) global entry2 entry2= Entry(root, width=15) entry2.grid(row=1, column=1) but =Button(root, text="submit" , width=10, command=submit , borderwidth=3, relief="solid") but.grid(row=2, column=1) global label3 label3=Label(root, text="") label3.grid(row=3, column=0)
Now, these lines of code are there main running lines of our alarm clock which makes the alarm clock work.
currenttime=time.strftime("%H:%M") alarmmessage=entry2.get() print(f"the alarm time is: {Alarmtime}") while Alarmtime!=currenttime: currenttime=time.strftime("%H:%M") time.sleep(1) if Alarmtime==currenttime: print("playing alarm sound...") winsound.PlaySound("C:/Users/sweta/Pictures/song_1.wav", winsound.SND_ASYNC) label3.config(text="Alarm sound playing>>>>>") messagebox.showinfo("alarm message", f"the message is: {alarmmessage}")
Submitted by Ayush Kumar JHA (akjayush)
Download packets of source code on Coders Packet
Comments