在wxpython应用程序中隐藏命令提示符 [英] Hiding command prompt in wxpython app

查看:223
本文介绍了在wxpython应用程序中隐藏命令提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用wxpython编写了一个gui应用程序,并使用py2exe将其转换为可执行文件。但是,每当我运行可执行文件时,命令提示符在后台出现,并在我退出程序时关闭。

I have written a gui application using wxpython and converted it into an executable using py2exe. However whenever I run the executable, the command prompt comes up in the background and closes when i exit the program. Is there any way to not make it appear?

推荐答案

您建议将应用程序类型设置为 console 在py2exe安装程序中:

You propply set the application type to console in py2exe setup:

setup(console=...

,而您需要使 Windows

setup(windows=...

这里我在一个名为 example.pyw 的文件中有一个简单的wxpython应用程序:

Here I have a simple wxpython application in a file named example.pyw:

# -*-coding: utf-8 -*-
#!python

# @file: example.pyw

import wx

class AppFrame(wx.Frame):
  def __init__(self, title, *args, **kwargs):
    super(AppFrame, self).__init__(None, title=title, *args, **kwargs)
    self.panel = wx.Panel(self)


class AppMain(wx.App):
  def OnInit(self):
    self.frame = AppFrame("Example")
    self.frame.Show()
    return True


AppMain(True).MainLoop()

这是一个名为 setup.py

# -*-coding: utf-8 -*-
#!python

# @file: setup.py

from distutils.core import setup
import py2exe

# http://msdn.microsoft.com/en-us/library/ms648009%28v=vs.85%29.aspx
RT_MANIFEST = 24

# http://en.wikipedia.org/wiki/Side-by-side_assembly
manifest = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
  <dependentAssembly>
    <assemblyIdentity
      type="win32"
      name="Microsoft.Windows.Common-Controls"
      version="6.0.0.0"
      processorArchitecture="*"
      publicKeyToken="6595b64144ccf1df"
      language="*"
    />
  </dependentAssembly>
</dependency>
<dependency>
  <dependentAssembly>
    <assemblyIdentity
      type="win32"
      name="Microsoft.VC90.CRT"
      version="9.0.21022.8"
      processorArchitecture="*"
      publicKeyToken="1fc8b3b9a1e18e3b"
      language="*"
    />
  </dependentAssembly>
</dependency>
</assembly>
"""

setup(
  windows = [{
    "script" : "example.pyw",
    # "icon_resources" : [(1, "icon.ico")] # have an icon?
    "other_resources" : [(RT_MANIFEST, 1, manifest)]
  }]
)

将它们放在同一目录中,并将 cd $ c> python setup.py py2exe :

put them in the same directory and cd to that directory and run python setup.py py2exe:

> python setup.py py2exe
running py2exe
creating C:\Users\XXX\build
creating C:\Users\XXX\build\bdist.win32
...
   KERNEL32.dll - C:\Windows\system32\KERNEL32.dll
   MSVCP90.dll - C:\Program Files\CMake 2.8\bin\MSVCP90.dll
   RPCRT4.dll - C:\Windows\system32\RPCRT4.dll
> 

如果一切顺利,你应该有一个名为 dist 的文件夹 example.exe 里面,运行它,它应该显示没有控制台的窗口。

if everything went well, you should have a folder named dist with example.exe inside. Run it and it should show the window without the console.

这篇关于在wxpython应用程序中隐藏命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆