Making alarm clock in replit

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:
problem5

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()

Regards

@emer2020 please put your code in backticks » ```
Have you tried pip install winsound in the shell (CTRL + SHIFT + S or CMD + SHIFT + S)?

Hi
I try doing that but here is the message that came up.
problem51
Regards

@emer2020 are you using Windows or another device, if your using another it wont work since winsound (win as in windows) is a windows module.

1 Like

Hi I am using windows.

Regards

@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.

1 Like

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.

6 Likes

Please don’t use wildcard imports as it’s bad practice

2 Likes

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.

2 Likes

Deploying the Repl makes it always always on. So it doesn’t even shut down for resources

1 Like

So that would be the only way to effectively run it. That costs 0.20 USD per day IIRC. Replit.com/pricing lists all options.

2 Likes

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.

1 Like

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.

1 Like