【发布时间】:2018-06-28 21:36:00
【问题描述】:
我正在开发一个播放音乐的程序,如果你按下按钮也会播放声音效果。我正计划制作它,以便它可以在任何计算机上运行,具有任何音效和音乐文件。所以我尝试用cx_freeze 将其设为.exe,但它只是在瞬间打开命令提示符,然后再次关闭它。有什么建议吗?
import pygame, time
import tkinter as tk
from pygame.locals import *
print ("WARNING: The program only accepts .wav files.")
musicDir = input("What is the FULL address of the music? (e.g C:\\Me\\Music\\music.wav) ")
soundDir = input("What is the FULL address of the music? (e.g C:\\Me\\Music\\sound.wav) ")
pygame.init() # initialize the pygame
soundObj = pygame.mixer.Sound(musicDir)
soundObj.play(loops=-1)
def playSound():
soundObj = pygame.mixer.Sound(soundDir)
soundObj.play()
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.LEFT)
sound = tk.Button(frame,
text="Play Sound Effect",
fg="green",
command=playSound)
sound.pack(side=tk.LEFT)
instruction = tk.Button(root,
text="Program by Will but really I just wanted another button because it looked cool.",
fg="blue")
instruction.pack(side=tk.BOTTOM)
root.mainloop()
【问题讨论】:
-
将 cx_freeze 生成的可执行文件拖到命令提示符中,并将输出粘贴到您的问题中。有很多事情可能会出错。
-
试过拖进去,一样的,闪开后又关上。
-
放置一个打印语句和文件的最开始,再次cx_freeze,然后再次将其拖入终端。看看它是否打印任何消息。
-
嗯,命令提示符的问题现在已经解决了,但是像往常一样,在编码时出现了一个新问题 "File "C:\Python 3.6\lib\tkinter_init_ .py", line 36, in
import _tkinter # If this failed your Python may not be configured for Tk ImportError: DLL load failed: The specified module could not be found." -
我猜你的构建是不完整的。也许this question 会帮助您正确构建可执行文件。
标签: python tkinter pygame cx-freeze