== Using py2exe to freeze your application == The following will explain how to freeze a Python/wxPython application using the [[http://www.py2exe.org/|py2exe]] tool. == What Objects are Involved == You will need a working development environment including * [[http://www.python.org/|Python]] * [[http://www.wxpython.org/|wxPython]] * [[http://www.py2exe.org/|py2exe]] * [[http://code.google.com/p/gui2exe/|Gui2Exe - by Andrea Gavana]] == Process Overview == A small sample wxPython "Hello world" application will be used to demonstrate the process. I created the tiny application using [[https://sourceforge.net/projects/boa-constructor/|Boa Constructor]] but you could use any other IDE you use for your wxPython development. I did the initial creation of the setup.py file with [[http://code.google.com/p/gui2exe/|Gui2Exe]] and then keep maintaining it and running it from the IDE (Boa in my case). == Python 2.5 == The setup.py needed for Python 2.5 or lower is shown on [[py2exe-python25|the py2exe for Python 2.5 page]]. == Python 2.6 == The setup.py needed for Python 2.6 is shown on [[py2exe-python26|the py2exe for Python 2.6 page]]. == Sample wxPython application == Save the following code in your working folder as a file called 'simplewx.py'. {{{ #!python #Boa:Frame:Frame1 import wx def create(parent): return Frame1(parent) [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1, ] = [wx.NewId() for _init_ctrls in range(5)] class Frame1(wx.Frame): def _init_coll_bsPanel_Items(self, parent): # generated method, don't edit parent.AddWindow(self.staticText1, 0, border=10, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.EXPAND) parent.AddSizer(self.fgsButtons, 1, border=2, flag=wx.ALL | wx.EXPAND) def _init_coll_fgsButtons_Items(self, parent): # generated method, don't edit parent.AddWindow(self.button1, 1, border=2, flag=wx.ALL | wx.EXPAND) parent.AddWindow(self.button2, 1, border=2, flag=wx.ALL | wx.EXPAND) def _init_coll_bsFrame_Items(self, parent): # generated method, don't edit parent.AddWindow(self.panel1, 1, border=2, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL) def _init_coll_fgsButtons_Growables(self, parent): # generated method, don't edit parent.AddGrowableCol(0) parent.AddGrowableCol(1) def _init_sizers(self): # generated method, don't edit self.bsPanel = wx.BoxSizer(orient=wx.VERTICAL) self.bsFrame = wx.BoxSizer(orient=wx.VERTICAL) self.fgsButtons = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=0) self._init_coll_bsPanel_Items(self.bsPanel) self._init_coll_bsFrame_Items(self.bsFrame) self._init_coll_fgsButtons_Items(self.fgsButtons) self._init_coll_fgsButtons_Growables(self.fgsButtons) self.SetSizer(self.bsFrame) self.panel1.SetSizer(self.bsPanel) def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(642, 279), size=wx.Size(236, 106), style=wx.DEFAULT_FRAME_STYLE, title='Frame1') self.SetClientSize(wx.Size(220, 70)) self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(2, 2), size=wx.Size(216, 66), style=wx.TAB_TRAVERSAL) self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1, label=u'Hello world!', name='staticText1', parent=self.panel1, pos=wx.Point(10, 10), size=wx.Size(196, 13), style=wx.ALIGN_CENTRE) self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1', name='button1', parent=self.panel1, pos=wx.Point(4, 37), size=wx.Size(100, 23), style=0) self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label='button2', name='button2', parent=self.panel1, pos=wx.Point(116, 37), size=wx.Size(100, 23), style=0) self._init_sizers() def __init__(self, parent): self._init_ctrls(parent) if __name__ == '__main__': app = wx.PySimpleApp() frame = create(None) frame.Show() app.MainLoop() }}} === Other wiki pages to check === * CreatingStandaloneExecutables * DistributingYourApplication * [[py2exeAndGettext]] * SmallApp === Comments === Please feel free to provide any feedback on this page either here, on the wxPython-user list or to werner.bruhin at free.fr.