How to pause song winsound with tkinter buttons?

347 Views Asked by At

I'm trying to make a music interface using tkinter and winsound, but when I press the button to play the song I can't click anything in the interface again until the song has finished playing. I'd like to be able to play and pause every song using the tkinter buttons (when I eventually add more songs).

import winsound
from tkinter import *

root = Tk()

def r_n_c():
    winsound.PlaySound("abcde.wav", winsound.SND_FILENAME)

def stop():
    winsound.PlaySound(None, winsound.SND_ASYNC)

rnc = Button(root, text = "Play Song", command = r_n_c)
rnc.grid()

stop_btn = Button(root, text = "Stop", command = stop)
stop_btn.grid(row = 1)

root.mainloop()
1

There are 1 best solutions below

0
On

Just add winsound.SND_ASYNC in r_n_c()

def r_n_c():
    winsound.PlaySound("abcde.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)


def stop():
    winsound.PlaySound(None, winsound.SND_ASYNC)