Created
June 26, 2016 00:54
-
-
Save charleyXuTO/edf153da4980e7ea68356a6f1edd3c44 to your computer and use it in GitHub Desktop.
An Alarm Clock created using Python and Tkinter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
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
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
how to import winsound?