Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Ẩn console file .exe PyInstaller trong Tkinter

Chuyển app Tkinter thành .exe bằng PyInstaller. Ẩn console bằng flag --windowed (hoặc -w).

Ví dụ

File app.py:

# Import thư viện
from tkinter import *

win = Tk()
win.geometry("700x350")
win.config(bg='#aad5df')

def display_text():
    Label(win, text="Hello World!", background='white', foreground='purple1').pack()

Button(win, text="Click Me", background="white", foreground="black", font=('Helvetica 13 bold'), command=display_text).pack(pady=50)
win.mainloop()

Lệnh build:

pyinstaller --onefile app.py --windowed

File .exe trong thư mục Dist. Chạy không hiện console.

Kết quả

Ứng dụng .exe mở cửa sổ Tkinter trực tiếp không có command shell.

Ẩn console file .exe PyInstaller trong Tkinter