0

I am creating an alarm using Python Tkinter. I have already completed the GUI part. Now, I want the alarm to ring automatically when the user-entered date and time arrive. How can I achieve this?

I am already aware of the Windows Task Scheduler (as I am a Windows user), but I have no idea how to integrate it into a Python script. Is it possible to automatically schedule a task using a Python script without manual intervention? If so, how can I achieve this, and which method should I use?

2
  • There are a few things to consider such as "should setting an alarm require admin?" this is required if you want to use task scheduler for each alarm. I would not recommend it for individual alarms, rather I would use task scheduler to start your program at login as a system tray application which runs all the time. This way admin is only needed at install time. I would use Tkinter for primary user interactions and windows notifications when the alarm goes off. Commented Jan 8, 2024 at 15:56
  • Do you need the Windows Task Scheduler somewhere? I mean, could you just play the alarm sound from python? Perhaps just use single thread dedicated to alarms, and add alarm tasks or a specific datetime from your main application using queues. Commented Jan 9, 2024 at 16:01

1 Answer 1

-1

You can start threading to run the function continuously in the background like

alarm_thread = threading.Thread(target=play_alarm)
alarm_thread.start()
time.sleep(1) 

in this play_alarm is the function that will run in the background

def play_alarm():
    frequency = 1500  # Hz
    duration = 3000  # milliseconds

    while alarm_playing:
        winsound.Beep(frequency, duration)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.