我使用了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)
您可以在此处找到相同的解决方案