Playing sound in background in python while GUI is running with tkinter

1.2k Views Asked by At

I have been trying to run sound in background while App is running. I am Arch Linux and Python 3.8 I have tried playsound as like this

playsound('music.mp3', False)

but I get error saying system not supported. I have also tried pygame following way:

from pygame import mixer
mixer.init()
mixer.music.load("music.mp3")
mixer.music.play()

But I get error pygame.error: Unrecognized audio format. Is there any other way I can run music in background some task is executing on GUI with tkinter. The program will run on arch and Ubuntu.

2

There are 2 best solutions below

3
On BEST ANSWER

Try this code it will run the background music continuously till the app is running

mixer.music.play(-1)
0
On

Try this:

mixer.music.play(-1)

And if you want your background music to be stopped in 10s then add this too:

gui_name.after(10000,  mixer.music.stop)

Hope it will help you.