I'm making a chiming clock in Tkinter and pygame. But, it echoes the sound on the hour, which is not what I want. How do I make it sound only once and without echoing? note: the variable clock.chime is an int for the chime mode (1, 2, 3, off), and clock is the main tkinter window. Here's my code:
while True:
try:
d = datetime.now() #updates time
hour = d.strftime("%I")
mins = d.strftime("%M")
secs = d.strftime("%S")
day = d.strftime("%A")
clock.update()
if mins=='00' and secs=='00' and clock.chime>0 and pygame.mixer.music.get_busy()==False: #chimes on the hour, but echoing
try:
pygame.mixer.music.load(str(clock.chime)+'.wav')
pygame.mixer.music.play()
except:
messagebox.showerror('Error', 'File '+str(clock.chime)+'.wav cannot be found.') #alerts if chime file is missing
time.sleep(0.01)
except: #detects when window is closed
break