from tkinter import *
import winsound
from winsound import PlaySound, SND_FILENAME, SND_LOOP, SND_ASYNC
root = Tk()
root.configure(background='light green')
def playing():
PlaySound('alarm', SND_FILENAME)
def stop_sound():
PlaySound(None, SND_FILENAME)
Button(root,text="playing ",font=("Helvetica 15"),command=playing).pack(pady=20)
Button(root,text="Stop",font=("Helvetica 15"),command=stop_sound).pack(pady=20)
root.mainloop()
Asked
Active
Viewed 29 times
0

Henry Ecker
- 34,399
- 18
- 41
- 57

Radha Rajput
- 1
- 1
-
Since you didn't specify the `SND_ASYNC` flag when playing the sound, the GUI was locked up until the sound finished - leaving nothing to be stopped by the other button, when your click was finally accepted. – jasonharper Dec 18 '21 at 04:47
-
Yes it's the `SND_ASYNC`. Try `PlaySound('alarm', SND_FILENAME|SND_ASYNC)` – Derek Dec 18 '21 at 05:21