简体   繁体   中英

Can I include music in my python game inside the code?

I want to use the winsound module in my text-based python game to play some background music, however I don't want the user to have to put the music files in the same folder as the game just to play it. Is there any way I can include the music in the file, so if I converrt it to an.exe file it will be included?

Some places online say winsound can use the audio data as a string for the winsound.PlaySound function, but how do you convert a.wav file to a string?

import winsound

winsound.PlaySound('song.wav', winsound.SND_FILENAME)
time.sleep(1)

Replace song.wav to any local .wav file you want to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM