Skip to content

Instantly share code, notes, and snippets.

@charleyXuTO
Created June 26, 2016 00:54
Show Gist options
  • Save charleyXuTO/edf153da4980e7ea68356a6f1edd3c44 to your computer and use it in GitHub Desktop.
Save charleyXuTO/edf153da4980e7ea68356a6f1edd3c44 to your computer and use it in GitHub Desktop.
An Alarm Clock created using Python and Tkinter
import tkinter
import winsound
import time
import math
def countdown(count):
seconds=math.floor(count%60)
minutes=math.floor((count/60)%60)
hours=math.floor((count/3600))
label['text'] ="Hours: "+ str(hours)+ " Minutes: " +str(minutes)+ " Seconds: " +str(seconds)
if count >= 0:
top.after(1000, countdown,count-1)
else:
for x in range(3):
winsound.Beep(1000,1000)
label['text']="Time is up!"
def updateButton():
hour,minute,sec=hoursE.get(),minuteE.get(),secondE.get()
if hour.isdigit() and minute.isdigit() and sec.isdigit():
time=int(hour)*3600+int(minute)*60+int(sec)
countdown(time)
top = tkinter.Tk()
top.geometry("250x150")
hoursT=tkinter.Label(top, text="Hours:")
hoursE=tkinter.Entry(top)
minuteT=tkinter.Label(top, text="Minutes:")
minuteE=tkinter.Entry(top)
secondT=tkinter.Label(top, text="Seconds:")
secondE=tkinter.Entry(top)
hoursT.grid(row=1,column=1)
hoursE.grid(row=1,column=2)
minuteT.grid(row=2,column=1)
minuteE.grid(row=2,column=2)
secondT.grid(row=3,column=1)
secondE.grid(row=3,column=2)
label = tkinter.Label(top)
label.grid(row=5,column=2)
button=tkinter.Button(top,text="Start Timer",command=updateButton)
button.grid(row=4,column=2)
top.mainloop()
@alle-likhitha
Copy link

how to import winsound?

@Polar001
Copy link

i tried adding this into my program under a class and commanded to a tkinter button however it just crashes and says im missing a positional argument

@hacksmith-CA
Copy link

i just deleted winsound from this code now it works! very well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment