【发布时间】:2020-08-17 16:23:48
【问题描述】:
所以我正在尝试使用 pyinstaller 将 tkinter 文件转换为可执行文件。我已经用图片完成了,但是当我创建包含某种音频的可执行文件时,它会显示“无法执行脚本 playmusic”(playmusic 是脚本名称)。我尝试使用 .wav 歌曲更改脚本名称,将 dist 文件夹中的 exe 与歌曲一起替换到脚本目录,但这些都不起作用。我也尝试过使用 auto-py-to-exe,但它不起作用。这首歌是用 pygame 播放的,并且在 VS Code 中没有任何问题。我使用的是 pyinstaller 还是其他模块都没关系。我在 Windows 10 上使用 python 3.8.2。
这是python脚本:
import tkinter as tk
from pygame import mixer, time
root = tk.Tk()
root.title("Music Player")
root.geometry("300x100+800+100")
label1=tk.Label(root, text="Start Song: ", fg='green', anchor="w")
label1.grid(row=0, column=0)
file = 'Ignite.mp3'
mixer.init()
mixer.music.load(file)
play = lambda: mixer.music.play()
button1 = tk.Button(root, text = 'Play', command = play)
while mixer.music.get_busy(): time.Clock().tick(10)
button1.grid(row=0, column=2)
pause = lambda: mixer.music.pause()
button2 = tk.Button(root, text="Pause", command = pause)
button2.grid(row=0, column=3)
resume = lambda: mixer.music.unpause()
button3 = tk.Button(root, text="Resume", command = resume)
button3.grid(row=0, column=4)
stop = lambda: mixer.music.stop()
button4 = tk.Button(root, text="Stop", command=stop)
button4.grid(row=0, column=5)
root.mainloop()
这是一种音乐播放器。 我运行来执行脚本的 pyinstaller 代码如下:
pyinstaller --add-data "Ignite.mp3;." --onefile -w playmusic.py
它执行没有问题,但是当我运行执行的脚本时,在弹出窗口中显示“无法执行脚本播放音乐”
【问题讨论】:
-
也分享你的
pyinstaller代码行 -
我已经编辑了问题 - 添加了脚本文件和 pyinstaller 代码
-
将函数传递给按钮的非常奇怪的方法,但尝试
pyinstaller -F -c playmusic.py,然后将音乐文件复制到exe所在的位置,如果弹出的控制台上仍然弹出任何错误,用那个编辑Q -
究竟有什么作用?我可以将其添加为答案
-
我用了命令'pyinstaller -F -c playmusic.py',把执行的脚本和歌曲放在同一个目录下。
标签: python-3.x tkinter pygame pyinstaller py2exe