Reputation: 705
The user has limited time to solve a problem. On the program, I run a music file at the same time as a GUI (tkinter) timer, and they both finish when the time is up. Some users may finish EARLY. I want to make the music stop when they close the timer window. 'winsound' does not accept 'stop()', and I am having no success with 'winsound.SND_PURGE'. This is more complicated than I thought. I tried this:
# python 3.5
winsound.PlaySound('The Countdown.wav', winsound.SND_FILENAME)
root = Tk() # IMAGINE this is a box with a number ticking down
root.mainloop()
root.protocol("WM_DELETE_WINDOW", winsound.SND_PURGE) # nothing happens :(
Is there a way of using flags? Perhaps an alternative audio-file player? Anything?
Let me know if you do. Thanks!
Upvotes: 0
Views: 168
Reputation: 9597
winsound.SND_PURGE
is just an integer constant, that happens to have the value of 64 (and furthermore, is documented as "not supported on modern Windows platforms"). What were you expecting root.protocol()
to do with it? You need to pass a function to be called when the window is closed. It looks like:
lambda: winsound.PlaySound(None, 0)
would be a suitable function for stopping sound playback, although I haven't actually tested it.
I think you're also going to need to add winsound.SND_ASYNC
to your original PlaySound call's flags, or your window won't even open until the sound is finished.
Upvotes: 1