使用 cxFreeze 冻结 wxPython 应用程序时如何隐藏控制台窗口?

发布于 2024-09-03 03:14:23 字数 216 浏览 7 评论 0原文

我正在使用 wxPython 开发一个 Python 应用程序并使用 cxFreeze 冻结它。除了以下几点之外,一切似乎都很顺利:

当我运行 cxFreeze 创建的可执行文件时,会弹出一个空白控制台窗口。我不想展示它。有什么办法可以隐藏它吗?

cxFreeze 网站上似乎没有记录该问题,除了 Py2Exe 的一些类似问题之外,谷歌搜索也没有发现太多问题。

谢谢。

I'm developing a Python application using wxPython and freezing it using cxFreeze. All seems to be going fine apart from this following bit:

When I run the executable created by cxFreeze, a blank console window pops up. I don't want to show it. Is there any way I could hide it?

It doesn't seem to be documented on the cxFreeze site and Googling didn't turn up much apart from some similar sorta problems with Py2Exe.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

在巴黎塔顶看东京樱花 2024-09-10 03:14:23

对于 Windows:

您必须使用这样的行(根据需要使用文件夹和名称)

C:/Python/Scripts/cxfreeze C:/Python/Code/yourprogram.py --base-name=Win32GUI --target-dir C:/Python/Dist

通过添加 --base-name=Win32GUI 选项,控制台窗口将不会出现。

For Windows:

You have to use a line like this (use file folders and names as appropriate)

C:/Python/Scripts/cxfreeze C:/Python/Code/yourprogram.py --base-name=Win32GUI --target-dir C:/Python/Dist

By adding the --base-name=Win32GUI option, the console window will not appear.

陌路终见情 2024-09-10 03:14:23

这在一定程度上起到了作用,但也存在问题。我的程序在控制台模式和 GUI 模式下运行。当使用 --console 参数从控制台运行时,它以控制台模式运行。当我按照下面的步骤操作时,这不再起作用,我的程序只是一个 GUI 应用程序。

以下源代码来自 \Python\Lib\site-packages\cx_Freeze\samples\PyQt4\setup.py 中的示例文件。当天的教训。阅读自述文件。

# A simple setup script to create an executable using PyQt4. This also
# demonstrates the method for creating a Windows executable that does not have
# an associated console.
#
# PyQt4app.py is a very simple type of PyQt4 application
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the application

import sys

from cx_Freeze import setup, Executable

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
        name = "simple_PyQt4",
        version = "0.1",
        description = "Sample cx_Freeze PyQt4 script",
        executables = [Executable("PyQt4app.py", base = base)])

This worked to some extent but it has issues. My program runs in both a console mode and a GUI mode. When run from the console with a --console argument it runs in a console mode. When I followed the procedure below, this doesn't work anymore and my program is only a GUI app then.

The following source code comes from a sample file in the \Python\Lib\site-packages\cx_Freeze\samples\PyQt4\setup.py. Lesson of the day. Read the README.

# A simple setup script to create an executable using PyQt4. This also
# demonstrates the method for creating a Windows executable that does not have
# an associated console.
#
# PyQt4app.py is a very simple type of PyQt4 application
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the application

import sys

from cx_Freeze import setup, Executable

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
        name = "simple_PyQt4",
        version = "0.1",
        description = "Sample cx_Freeze PyQt4 script",
        executables = [Executable("PyQt4app.py", base = base)])
時窥 2024-09-10 03:14:23

如果您使用的是 Windows,则可以将“主”脚本的扩展名(启动应用程序)重命名为 .pyw

If you're using Windows, you could rename your "main" script's extension (that launches the app) to .pyw

因为看清所以看轻 2024-09-10 03:14:23

选项 1)使用 gui2exe 来处理各种选项。

选项 2)使用“base”参数修改 setup.py。

GUI2Exe_Target_1 = Executable(
    # what to build
    script = "rf_spi.py",
    initScript = None,
    base = 'Win32GUI',  # <-- add this
    targetDir = r"dist",
    targetName = "rf_spi.exe",
    compress = True,
    copyDependentFiles = False,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = r"wireless.ico"
    )

Option 1) Use gui2exe to muck with various options.

Option 2) Modify your setup.py with 'base' parameter as such.

GUI2Exe_Target_1 = Executable(
    # what to build
    script = "rf_spi.py",
    initScript = None,
    base = 'Win32GUI',  # <-- add this
    targetDir = r"dist",
    targetName = "rf_spi.exe",
    compress = True,
    copyDependentFiles = False,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = r"wireless.ico"
    )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文