2010-05-21 56 views
30

我正在開發一個使用wxPython的Python應用程序並使用cxFreeze將其凍結。除了以下幾點,似乎都很好:如何在使用cxFreeze凍結wxPython應用程序時隱藏控制檯窗口?

當我運行由cxFreeze創建的可執行文件時,會彈出一個空白的控制檯窗口。我不想展示它。有什麼方法可以隱藏它嗎?

它似乎沒有記錄在cxFreeze網站上,谷歌搜索沒有從Py2Exe中發現一些類似的問題。

謝謝。

回答

18

這個工作在一定程度上,但它有問題。我的程序以控制檯模式和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

如果你使用的是Windows,你可以重命名你的「主」腳本的擴展名(啓動應用程序),以.pyw

+3

這似乎沒有工作。我將它重命名爲PYW,但它仍然彈出。 – 2010-05-21 13:53:48

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

對於Windows:

你必須使用這樣的線(使用文件夾和名稱如適用)

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

通過添加--base-name=Win32GUI選項,控制檯窗口將不會出現。

相關問題