I am trying to make a alarm clock in python using tkinter. I have a problem with import winsound module. I was wondering if anyone could help me.
Here is the code and error message:
from tkinter import *
import datetime
from tkinter.messagebox import *
from tkinter.ttk import *
import winsound
MainWindow=Tk()
MainWindow.title("Alarm clock by PythonGeeks")
MainWindow.config(bg="grey")
MainWindow.geometry("600x300")
def Alarm():
if a1.get()=="AM":
x=int(b1.get())
y=int(b2.get())
if a1.get()=="PM":
x=int(b1.get())+12
y=int(b2.get())
showinfo("notification", "alarm has been set")
while True:
if x == datetime.datetime.now().hour and y == datetime.datetime.now().minute:
for j in range(0,100):
winsound.Beep(1000,100)
break
label1=Label(MainWindow,text="HOURS:")
label2=Label(MainWindow,text="MINUTES:")
label1.place(relx=0.1,rely=0.1)
label2.place(relx=0.5,rely=0.1)
b1=Entry(MainWindow)
b2=Entry(MainWindow)
b1.place(relx=0.2,rely=0.1)
b2.place(relx=0.6,rely=0.1)
c1=Button(MainWindow,text="Set Alarm",command=Alarm)
c1.place(relx=0.4,rely=0.5)
a1=Combobox(MainWindow,values=["AM","PM"])
a1.place(relx=0.42,rely=0.3)
label3=Label(MainWindow,text="AM OR PM:")
label3.place(relx=0.3,rely=0.3)
mainloop()
@emer2020 it should be working, since you have import winsound. When I mean windows are you using Windows OS? That’s all winsound runs with. If you are change the Categorie to Bug Reports since it should work with what I know.
Repls run on Linux, which doesn’t support winsound.
You could use replit audio instead but for it to work on Safari / for other users you’d have to create a website.
I would not recommend making an alarm clock on Replit. If you get sound to work (which I’m told that sound in Python on Replit can be tricky at times), the Repl will still not stay always on. Even “always on” merely turns your Repl back on when it shuts off, but the shut off would reset your program (unless you hardcoded it), thus preventing the alarm from sounding at the designated time and thereby not waking you up (or whatever you’re using it for). AFAIK, deployments will still reboot as well. Now, coding a Python alarm clock to work on your PC (such as Windows) would be a fun way to wake up in the morning. It is a cool idea; I just wanted to let you know the potential issues with using Replit for this particular project.
You make the assumption that you have to use delays like sleep, you could instead just check the current time which would probably work relatively well with always on.
That is brilliant. Using that, we could then make the alarm ring if the time is between x and y (to ensure that if it reboots at the designated time it would still go off), it would work. x and y can be the time and the time + a designated amount of time. Thank you for that idea.