python3 gui (tkinter) on windows to exe file
เริ่มแรก ก็ pipก่อน
pip install pyinstaller
จากนั้นทดสอบ ดู
pyinstaller –version
หาก เรื่องใคร ไม่ได้ ทำ pip ให้เป็นคำสั่งไว้ก็ให้ไป pip ที่นี้นะ
C:\Users\ratta\AppData\Local\Programs\Python\Python37\Scripts
และหาก เป็นแบบนี้ คำสั่ง pyinstaller ก็จะ อยู่ที่นี้ไปด้วย ดังนั้น หาก file python อยู่ที่อืน ก็ ลอง run ทำ ไฟล์ exe แบบนี้นะ
C:\Users\ratta\AppData\Local\Programs\Python\Python37\Scripts\pyinstaller test.py
หรือสรุป คำสั่งก็คือ pyinstaller test.py
จากนั้นจะได้โฟเดอร์ dist เข้าไปจะเจอ ไฟล์ .exe ตามชื่อไฟล์ที่เราทดสอบ ในที่นี้จะเป็น test.exe
ลอง runดู หาก ไม่ได้ ให้ลอง runผ่าน cmd จะมี error ขึั้นมา
หากเรามีไฟล์รูป ให้ copy ลง โฟเดอร์ dist ด้วยไม่งั้น run ไม่ผ่าน
พอทำการ run exe จะพบ ว่า จะมี console ติดมาด้วย หากต้องการ disable ให้ สั่งตามนี้
pyinstaller –noconsole test.py