Background Music for Python Games

python

#1

Hello! I just started making this text-based game via Python (it doesn't use Pygame), and I'm thinking I may want background music for it in the future. How would I go about doing this?


#2

you could try adding something to the beginning of your python file that opens an external html file that only plays a song on loop or something as soon as you execute the python file.


#3

how would you do that


#4

check this out


#5

I'll try that, then report back.


#6

Alright so I did some more searching and found an actual solution...

Add this to your code:

import webbrowser

new = 2

url = "file://path"
# eg: "file://C:/Users/Student/Desktop/pytest.html"

webbrowser.open(url, new=new)

You can refer to: this link


#7

So to summarize, you need to write your own html file that plays a song of your choice and then after you create the file, link to it with the above method, and you're good to go :)


#8

Thanks to both of you!

P.S. kogeyamauchiha, congratulations for being a Naruto fan. :slight_smile: