我正在使用WXPYTHON开发Python应用程序,并使用CXFREEZE冻结它。除了以下几点外,一切似乎都很好:

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

它似乎没有在CXFREEZE网站上进行记录,除了PY2EXE的某些类似问题外,Google Google并没有出现太多。

谢谢。

有帮助吗?

解决方案

这在某种程度上起作用,但有问题。我的程序在控制台模式和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)])

其他提示

对于Windows:

您必须使用这样的行(适当使用文件文件夹和名称)

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

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

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

选项1)使用 gui2exe 给有各种选择的笨蛋。

选项2)这样,用“基础”参数修改您的设置。

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"
    )
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top