我使用 tkinter 创建了简单的 GUI,然后使用 cx_Freeze 创建了 .exe 文件,当我打开 .exe 文件时,它显示控制台而不是 GUI 窗口。我想要的是隐藏控制台,只是为了显示 GUI 窗口。
- python 3.6.3
- cx_Freeze 5.1.1
- 平台:macOS Sierra 10.12
hello.py文件代码:
from tkinter import Tk, Label, Button, BOTTOM
root = Tk()
root.title('Button')
Label(text='Hello').pack(pady=15)
Button(text='Button').pack(side=BOTTOM)
root.mainloop()
setup.py文件代码:
from cx_Freeze import setup, Executable
base = None
executables = [
Executable('hello.py', base=base)
]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
executables=executables
)
将其添加到 setup.py 文件中(主要问题)
import sys
base = 'Win32GUI' if sys.platform == 'win32' else None
这也是(只是为了预防)
buildOptions = dict(
packages=['scrollFrame', 'searchSetup', "tkinter", "threading", "sqlite3", "openpyxl", "re"],
include_msvcr=True,
excludes=['numpy', 'scipy', 'matplotlib', 'pandas', 'jinja2', 'flask']
)
将其添加到您的 setup() 函数中
options=dict(build_exe=buildOptions)
完整代码-
from cx_Freeze import setup, Executable
# To compile for windows use---> python setup.py bdist_msi
# To compile for mac use---> python setup.py bdist_dmg
buildOptions = dict(
packages=['scrollFrame', 'searchSetup', "tkinter", "threading", "sqlite3", "openpyxl", "re"],
include_msvcr=True,
excludes=['numpy', 'scipy', 'matplotlib', 'pandas', 'jinja2', 'flask']
)
import sys
base = 'Win32GUI' if sys.platform == 'win32' else None
executables = [
Executable('MedSort.py', base=base)
]
setup(name='MedSort',
version='2.0',
description='Medical Indent management',
options=dict(build_exe=buildOptions),
executables=executables)
您可以找到相同问题的解决方案 here
我是一名优秀的程序员,十分优秀!