Introduction
The following will explain how to freeze a Python/wxPython application using the py2exe tool.
What Objects are Involved
You will need a working development environment including
* Python * wxPython * py2exe * Gui2Exe - by Andrea Gavana
Process Overview
A tiny sample wxPython "Hello world" application will be used to demonstrate the process. I created the tiny application using Boa Constructor but you could use any other IDE you use for your wxPython development. The creation of the setup.py file I did using Gui2Exe, but again one could create this by hand.
Special Concerns
Python 2.5x
- you will need the MS C run time dll (msvcr71.dll)
Python 2.6x
- you will need the MS C run time dll's (msvcr90.dll, msvcp90.dll, msvcm90.dll)
- you will a Microsoft.VC90.CRT.manifest file
Sample wxPython application
Create a folder and save the following code as a file called 'simplewx.py'.
1 #Boa:Frame:Frame1
2
3 import wx
4
5 def create(parent):
6 return Frame1(parent)
7
8 [wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1,
9 ] = [wx.NewId() for _init_ctrls in range(3)]
10
11 class Frame1(wx.Frame):
12 def _init_coll_bsPanel_Items(self, parent):
13 # generated method, don't edit
14
15 parent.AddWindow(self.staticText1, 0, border=10,
16 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.EXPAND)
17
18 def _init_coll_bsFrame_Items(self, parent):
19 # generated method, don't edit
20
21 parent.AddWindow(self.panel1, 1, border=2,
22 flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
23
24 def _init_sizers(self):
25 # generated method, don't edit
26 self.bsPanel = wx.BoxSizer(orient=wx.VERTICAL)
27
28 self.bsFrame = wx.BoxSizer(orient=wx.VERTICAL)
29
30 self._init_coll_bsPanel_Items(self.bsPanel)
31 self._init_coll_bsFrame_Items(self.bsFrame)
32
33 self.panel1.SetSizer(self.bsPanel)
34 self.SetSizer(self.bsFrame)
35
36 def _init_ctrls(self, prnt):
37 # generated method, don't edit
38 wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
39 pos=wx.Point(642, 279), size=wx.Size(124, 86),
40 style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
41 self.SetClientSize(wx.Size(108, 50))
42
43 self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
44 pos=wx.Point(2, 2), size=wx.Size(104, 46),
45 style=wx.TAB_TRAVERSAL)
46
47 self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
48 label=u'Hello world!', name='staticText1', parent=self.panel1,
49 pos=wx.Point(10, 10), size=wx.Size(84, 13),
50 style=wx.ALIGN_CENTRE)
51
52 self._init_sizers()
53
54 def __init__(self, parent):
55 self._init_ctrls(parent)
56
57
58 if __name__ == '__main__':
59 app = wx.PySimpleApp()
60 frame = create(None)
61 frame.Show()
62
63 app.MainLoop()
Sample wxPython application
Create a folder and save the following code as a file called 'simplewx.py'.
1 #Boa:Frame:Frame1
2
3 import wx
4
5 def create(parent):
6 return Frame1(parent)
7
8 [wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1,
9 ] = [wx.NewId() for _init_ctrls in range(3)]
10
11 class Frame1(wx.Frame):
12 def _init_coll_bsPanel_Items(self, parent):
13 # generated method, don't edit
14
15 parent.AddWindow(self.staticText1, 0, border=10,
16 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.EXPAND)
17
18 def _init_coll_bsFrame_Items(self, parent):
19 # generated method, don't edit
20
21 parent.AddWindow(self.panel1, 1, border=2,
22 flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
23
24 def _init_sizers(self):
25 # generated method, don't edit
26 self.bsPanel = wx.BoxSizer(orient=wx.VERTICAL)
27
28 self.bsFrame = wx.BoxSizer(orient=wx.VERTICAL)
29
30 self._init_coll_bsPanel_Items(self.bsPanel)
31 self._init_coll_bsFrame_Items(self.bsFrame)
32
33 self.panel1.SetSizer(self.bsPanel)
34 self.SetSizer(self.bsFrame)
35
36 def _init_ctrls(self, prnt):
37 # generated method, don't edit
38 wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
39 pos=wx.Point(642, 279), size=wx.Size(124, 86),
40 style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
41 self.SetClientSize(wx.Size(108, 50))
42
43 self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
44 pos=wx.Point(2, 2), size=wx.Size(104, 46),
45 style=wx.TAB_TRAVERSAL)
46
47 self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
48 label=u'Hello world!', name='staticText1', parent=self.panel1,
49 pos=wx.Point(10, 10), size=wx.Size(84, 13),
50 style=wx.ALIGN_CENTRE)
51
52 self._init_sizers()
53
54 def __init__(self, parent):
55 self._init_ctrls(parent)
56
57
58 if __name__ == '__main__':
59 app = wx.PySimpleApp()
60 frame = create(None)
61 frame.Show()
62
63 app.MainLoop()
Comments
This is the place that you can add your plans for the future of this page, tell people how to contact you, or leave feedback for the author of the page.