Python writes an alarm clock function
- 2020-06-12 09:32:02
- OfStack
Put the audio file in the same directory as the.py file
import winsound # Import this module for sound playback
import time # Import this module to get the current time
# Prompt the user to set the time and minutes
my_hour = input(" Please enter: ")
my_minute = input(" Please enter points: ")
flag = 1
while flag:
t = time.localtime() # Era value of the current time
fmt = "%H %M"
now = time.strftime(fmt, t) # Converts an era value to a string containing hours and minutes
now = now.split(' ') # Cut with a space to put the time and into the name now The list of
hour = now[0]
minute = now[1]
if hour == my_hour and minute == my_minute:
music = 'Good Time.wav'
winsound.PlaySound(music, winsound.SND_ALIAS)
flag = 0