Search code examples
pythonalarm

How do I continously check if a statement is true


I wrote this short program to make an alarm. Basically you choose a time to set the alarm and it will play analog-watch-alarm_daniel-simion.wav. I have tried using a while True: statement but that didn't seem to work. Can someone please help?

import time
import datetime
import winsound
from datetime import datetime
lcltime =datetime.now().strftime('%H:%M')
print(lcltime)
while True:
    if lcltime == "22:33":
        winsound.PlaySound("analog-watch-alarm_daniel-simion.wav",  winsound.SND_ALIAS)
        break

Solution

  • You should put this line lcltime=datetime.now().strftime('%H:%M') inside the while loop.