저는 음악을 재생하고 버튼을 누르면 음향 효과도 재생하는 프로그램을 작업 중입니다. 사운드 효과와 음악 파일이있는 모든 컴퓨터에서 작동하도록 만들 계획이었습니다. 그래서 나는 그것을 .exe
with로 만들려고 시도했지만 cx_freeze
잠시 동안 명령 프롬프트를 연 다음 다시 닫습니다. 팁이 있습니까?
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로 똑같이 할 수 없으며 내 코드는 .exe없이 완벽하게 작동합니다. 나는 문제를 해결하기 위해 인터넷에서 몇 가지 시도했지만 헛된 것입니다.
그러나 정말로 .exe를 만들고 싶다면 가장 좋은 옵션 중 하나는 pyinstaller입니다. 나는 항상 그것을 사용합니다.
설치하기 위해서:
sudo -H pip3 install pyinstaller
쓰다:
pyinstaller test_file.py
그런 다음 "dist"디렉토리로 이동하여 프로젝트 이름을 딴 폴더를 입력하십시오. 거기에는 상당히 많은 파일이 있습니다. 그러나 필요한 하나의 .exe 파일이 있습니다. 따라서 클릭하여 실행하십시오.
항목을 사용하지 않고 파일의 주소를 입력하려면 다음을 사용하십시오 (좋아 보이고 오류가 없습니다).
from tkinter import filedialog as fd
filename = fd.askopenfilename()
if filename:
print (filename)
도움이 되었기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다