...
/Advanced cx_Freeze - Using a setup.py File
Advanced cx_Freeze - Using a setup.py File
We'll cover the following...
First off we need a script to use. We will use the wxPython form example from the previous chapters.
Press + to interact
import wxclass DemoPanel(wx.Panel):""""""def __init__(self, parent):"""Constructor"""wx.Panel.__init__(self, parent)labels = ["Name", "Address", "City", "State", "Zip","Phone", "Email", "Notes"]mainSizer = wx.BoxSizer(wx.VERTICAL)lbl = wx.StaticText(self, label="Please enter your information here:")lbl.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))mainSizer.Add(lbl, 0, wx.ALL, 5)for lbl in labels:sizer = self.buildControls(lbl)mainSizer.Add(sizer, 1, wx.EXPAND)self.SetSizer(mainSizer)mainSizer.Layout()def buildControls(self, label):"""Put the widgets together"""sizer = wx.BoxSizer(wx.HORIZONTAL)size = (80,40)font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)lbl = wx.StaticText(self, label=label, size=size)lbl.SetFont(font)sizer.Add(lbl, 0, wx.ALL|wx.CENTER, 5)if label != "Notes":txt = wx.TextCtrl(self, name=label)else:txt = wx.TextCtrl(self, style=wx.TE_MULTILINE, name=label)sizer.Add(txt, 1, wx.ALL, 5)return sizerclass DemoFrame(wx.Frame):"""Frame that holds all other widgets"""def __init__(self):"""Constructor"""wx.Frame.__init__(self, None, wx.ID_ANY,"Py2Exe Tutorial",size=(600,400))panel = DemoPanel(self)self.Show()if __name__ == "__main__":app = wx.App(False)frame = DemoFrame()app.MainLoop()
Now let’s create a setup.py file in the cx_Freeze style:
Press + to interact
# setup.pyfrom cx_Freeze import setup, Executablesetup(name = "wxSampleApp",version = "0.1",description = "An example wxPython script",executables = [Executable("sampleApp.py")])
As you can see, this is a pretty simple one. We import a couple classes from cx_Freeze and pass some parameters into them. In this case, we give the setup class a name, version, description and ...