【问题标题】:how to hide console using cx_Freeze on OSX如何在 OSX 上使用 cx_Freeze 隐藏控制台
【发布时间】:2018-02-23 23:05:02
【问题描述】:

我使用 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
  )

【问题讨论】:

  • 可能的解决方法使用网站,我绝不承担任何责任,py2exe.net

标签: python macos tkinter cx-freeze


【解决方案1】:

在你的 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 setup.py bdist_msi,适用于 Windows 和 Mac:python setup.py bdist_dmg。没想到和linux中的python setup.py build不一样!
猜你喜欢
  • 2011-07-28
  • 1970-01-01
  • 2012-05-25
  • 2022-11-17
  • 2014-09-27
  • 1970-01-01
  • 2011-08-31
  • 2023-03-09
  • 2017-09-20
相关资源
最近更新 更多