Reputation: 2295
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?
Upvotes: 1
Views: 1830
Reputation:
You propply set the application type to console
in py2exe setup:
setup(console=...
while you need to make it windows
:
setup(windows=...
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()
this is a simple setup in a file named 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)]
}]
)
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
>
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.
Upvotes: 2