How can I hide the console window when freezing wxPython applications with cxFreeze?

旧巷老猫 提交于 2019-12-17 21:47:11

问题


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.


回答1:


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)])



回答2:


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.




回答3:


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




回答4:


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"
    )


来源:https://stackoverflow.com/questions/2880316/how-can-i-hide-the-console-window-when-freezing-wxpython-applications-with-cxfre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!