오늘 파이썬을 배우기 시작했습니다. 필자는 PHP 만 사용하여 다양한 용도로 사용할 수 있었으며 EXE 파일을 작성하는 데 신경 쓸 필요가 없었습니다.파이썬 3.4 GUI 실행 파일
import winsound
from tkinter import *
class Application(Frame):
def __init__(self, master):
Frame.__init__(self,master)
self.pack()
self.counts = 0
self.create_widgets()
def create_widgets(self):
Label(self, text = "Test Label").pack()
self.button = Button(self, text = "click", command = self.update_text).pack()
self.result = Label(self, text = "Clicked 0 times")
self.result.pack()
def update_text(self):
self.counts += 1
self.result["text"] = "Clicked " + str(self.counts) + " times"
winsound.PlaySound('sound1.wav', winsound.SND_FILENAME | winsound.SND_ASYNC)
root = Tk()
root.title("Title")
root.geometry("300x120")
app = Application(root)
root.mainloop
응용 프로그램 아래와 같이 나는 무작위로 "당신이 클릭 한 몇 번이나"응용 프로그램을 함께했다 일부 인터넷 파이썬 프로그래밍 튜토리얼과 내 자신의 편집의 약간을 사용
는잘 작동하지만 문제는 때 시작 내가 작은 "뭔가 좀 더 쉽게"프로그램을 작성하고자하는 편의상 이유를 위해 하나의 EXE 파일을 컴파일하려고했습니다. Py2Exe는 번들 파일 1로 프로그램을 컴파일하고 싶지 않습니다. PyInstaller는 --onefile을 사용하여 컴파일했지만 실행시 응용 프로그램은 tkinter 오류 이상을 제공하지 않습니다.
GUI로 작은 하나의 exe 파일을 만드는 방법이 있습니까? 아니면 막 다른 골목입니까? 나는 거짓말을하지는 않지만 파이썬을 배우고 PHP에서 가능하지 않은 웹 및 데스크톱 응용 프로그램에서 사용할 수 있다는 아이디어를 정말 좋아했습니다.
저는 Python 3.4를 사용 중이며 py2exe 및 Python 3.3 - 3.4 용 PyInstaller를 테스트했습니다.
편집 : 샘플 py2exe에 대한 setup.py 및 오류
from distutils.core import setup
import py2exe
setup(windows=[{"script": "text.py"}],
options = {"py2exe": {"bundle_files": 1}
})
오류
C:\Users\SEJBR\Desktop\Python>python setup.py py2exe
running py2exe
1 missing Modules
------------------
? readline imported from cmd, code, pdb
OOPS: tkinter 2
pyInstaller 중에 컴파일 오류
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'Tkinter'
2515 ERROR: TCL/TK seams to be not properly installed on this system
py2exe에서 console 대신 window 인수를 사용 했습니까? –
예. 나는 setup과 bundle_files에 windows를 사용했다 : setup> 옵션에서 1 번, py2exe는 Missing Module을 준다. OOPS : tkinter 2는 2보다 낮은 bundle_files 때문에 발생한다. 그러나 bundle_files가 1보다 높으면 하나의 실행 파일에 대해서 이야기 할 필요가 없다. 질문을 편집하고 샘플 py2exe setup.py를 추가했으며 오류가 발생했습니다. – SEJBR
py2exe에 익숙하지 않지만 PyInstaller를 사용하면 어떤 오류가 발생 했습니까? – fhdrsdg