【问题标题】:How can I hide the console window when freezing wxPython applications with cxFreeze?使用 cxFreeze 冻结 wxPython 应用程序时如何隐藏控制台窗口?
【发布时间】:2011-02-22 05:53:39
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

    标签: python wxpython cx-freeze


    【解决方案1】:

    这在一定程度上有效,但存在问题。我的程序在控制台模式和 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)])
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        对于 Windows:

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

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

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

        【讨论】:

          【解决方案4】:

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

          【讨论】:

          • 这似乎不起作用。我将它重命名为 PYW 但它仍然弹出。
          猜你喜欢
          • 2017-08-03
          • 2016-03-30
          • 2011-04-20
          • 2011-04-04
          • 1970-01-01
          • 2011-06-19
          • 1970-01-01
          • 2011-03-17
          • 1970-01-01
          相关资源
          最近更新 更多