Search code examples
pythonpygamepython-playsound

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


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.


Solution

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

    mixer.music.play(-1)