gpt4 book ai didi

python - 如何在 OSX 上使用 cx_Freeze 隐藏控制台

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:07 24 4
gpt4 key购买 nike

我使用 tkinter 创建了简单的 GUI,然后使用 cx_Freeze 创建了 .exe 文件,当我打开 .exe 文件时,它显示控制台而不是 GUI 窗口。我想要的是隐藏控制台,只是为了显示 GUI 窗口。

  1. python 3.6.3
  2. cx_Freeze 5.1.1
  3. 平台: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

关于python - 如何在 OSX 上使用 cx_Freeze 隐藏控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48957469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com