Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

tkinter - Python - pygame error when executing exe file

So, I'm working on a little project for myself, using pygame and tkinter to build an mp3 player. Everything works when running the program using visual studio, but when I turned the program to an .exe file using pyinstaller and tried to run in, the following appeared:
pygame.mixer.load(song)
pygame.error
Failed to execute script

I've tried everything, but it keeps telling me the same. Here you can see how I call the song:

pygame.init()
pygame.mixer.init()

song = path + 'music\' + selected_song
pygame.mixer.music.load(song)

Being path + 'music\' , the directory where the songs are. And slected_song the name of the song + '.mp3'.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need double backslashes:

From:

song = path + 'music\' + selected_song

To:

song = path + '\music\' + selected_song

Or:

song = f"{path}\{music}\{selected_song}"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...