Python / Windows GUI programming with wxPython
[
Front page
] [
New
|
List of pages
|
Search
|
Recent changes
]
Start:
[[Software]]
* Introduction [#l2af1518]
** Overview [#d74d8005]
>
This article explains how to create GUI interface with Py...
** Targeted Audience [#a5101515]
>
The targeted audience of this article is expected to have...
** About wxPython [#q60e7beb]
>
wxPython is a GUI tool kit, which can work with Python. T...
* Using wxPython [#k5d37d57]
** Displaying window [#z0a5a518]
>
Let's start writing an application, which simply displays...
>
>>
&ref(sample_2_1.jpg);~
>
Its source code is shown below.
>
- sample_2_1.py
>>
import wx
class SampleApp(wx.App):
def OnInit(self):
self.init_frame()
return True
def init_frame(self):
self.frm_main = wx.Frame(None)
self.frm_main.SetTitle("Hello, wxPython!")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
sample_2_1.py is the basic and standard form of wxPython ...
First, ?SampleApp? class, which inherits ?wx.App,? is def...
** Placing Controls [#zb80bb62]
>
Let's put several Controls on the window.
>
>>
&ref(sample_2_2.jpg);~
>
The source code is show below.
- sample_2_2.py
>>
import wx
class SampleApp(wx.App):
def OnInit(self):
self.init_frame()
return True
def init_frame(self):
self.frm_main = wx.Frame(None)
self.sizer = wx.BoxSizer()
self.frm_main.SetSizer(self.sizer)
self.txt_title = wx.TextCtrl(self.frm_main)
self.sizer.Add(self.txt_title, 1, wx.ALIGN_CENTE...
self.btn_submit = wx.Button(self.frm_main)
self.btn_submit.SetLabel("Submit")
self.sizer.Add(self.btn_submit, 0, wx.ALIGN_CENT...
self.frm_main.SetTitle("sample_2_2")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
?wx.TextCtrl? and ?wx.Button? are placed in on the window...
>
>>
&ref(sample_2_2_sizer.jpg);~
** Processing events [#h300a60f]
>
Let's see how events are processed as controls are used. ...
>
>>
&ref(sample_2_3.jpg);~
>
The source code of sample_2_3 is shown below
- sample_2_3.py
>>
import wx
class SampleApp(wx.App):
def OnInit(self):
self.init_frame()
return True
def init_frame(self):
self.frm_main = wx.Frame(None)
self.sizer = wx.BoxSizer()
self.frm_main.SetSizer(self.sizer)
self.txt_title = wx.TextCtrl(self.frm_main)
self.sizer.Add(self.txt_title, 1, wx.ALIGN_CENTE...
self.btn_submit = wx.Button(self.frm_main)
self.btn_submit.SetLabel("Change Title")
self.btn_submit.Bind(wx.EVT_BUTTON, self.on_subm...
self.sizer.Add(self.btn_submit, 0, wx.ALIGN_CENT...
self.frm_main.SetTitle("sample_2_3")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
def on_submit(self, event):
self.frm_main.SetTitle(self.txt_title.GetValue())
self.txt_title.SetValue("")
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
The basic structure of this program is very similar to sa...
* Creating GUI with wxGlade [#r7ba8fef]
** what is wxGlade? [#ydb558f8]
>
In previous sections, xwPython enables to GUI programming...
>
wxGlade employs a simple drag-and-drop method, and GUI Co...
>
When GUI location data is output as a part of Python sour...
** How to use wxGlade [#j6cf106e]
>
wxGlade is consists of three windows. As booting wxGlade,...
>
- Main window
>>
&ref(wxglade_main.png);~
>
- Tree window
>>
&ref(wxglade_tree.png);~
>
- Porperty window
>>
&ref(wxglade_prop.png);~
>
In Main window, GUI parts, such as Frame and Control, are...
The details of how these windows work will be explained i...
** Displaying windows [#ea2e9cbf]
>
At the beginning, let's displays a simple window.
>
>>
&ref(sample_3_3.png);~
>
To execute this application, its appearance is almost ide...
>
To boot wxGlade, the basic information of configuration (...
- The output format is specified to the XRC format.
- At Encoding section, UTF-8 is selected.
- The output file is named.
>
>>
&ref(sample_3_3_property.png);~
>
As finishing the modification of the basic information, ...
>
>>
&ref(sample_3_3_select_frame_class.png);~
>
Then, ?frame_1? is added to Tree windows, and a new desig...
>
>>
&ref(sample_3_3_tree.png);~
>
To select ?frame_1? at Tree window, it allows editing Fra...
>
>>
&ref(sample_3_3_property_frame.png);~
>
This is an image as Design displays a window, which wxGla...
>
>>
&ref(sample_3_3_design.png);~
>
The window title and other specific configurations are re...
>
>>
&ref(sample_3_3_generate_code.png);
>
The output is shown below.
- sample_3_3.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Wed Nov 16 22:19:37 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<title>frame_main</title>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
</object>
</object>
</resource>
>
The source code, which enables sample_3.3 to create a win...
- sample_3.3.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_3.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.frm_main.SetTitle("sample_3_3")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
At the line of 8, ?xrc.XmlResource(XRC_FILE)? reads the X...
** Placing a Control [#m342633a]
>
Next, this shows how to place Controls. Put ?wx.TextCtrl?...
>
>>
&ref(sample_3_4.png);~
>
As explained in the previous sections, Controls need ?wx....
>
>>
&ref(sample_3_4_sizer.png);~
>
?Add a TextCtrl? is selected from Main window, and ?wx.Te...
>
>>
&ref(sample_3_4_design.png);~
>
To configure the name attribute of Control, output the so...
- sample_3_4.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Wed Nov 16 22:15:53 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<size>400, 300</size>
<title>main_frame</title>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxTextCtrl" name="text_in...
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxButton" name="button_su...
<label>Submit</label>
</object>
</object>
</object>
</object>
</resource>
>
The source code of displaying a window defines two tasks:...
- sample_3_4.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_4.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.txt_input = xrc.XRCCTRL(self.frm_main, "tex...
self.btn_submit = xrc.XRCCTRL(self.frm_main, "bu...
self.frm_main.SetTitle("sample_3_4")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
As the source code of sample_3_4 shows, an upside of usin...
** Event processing [#ddfea2a0]
>
Event processing is added to sample_3_4. The basic functi...
>
>>
&ref(sample_3_5.png);
>
Since there is no change in the locations of GUI parts, X...
- sample_3_5.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Wed Nov 16 22:16:28 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<size>400, 300</size>
<title>main_frame</title>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxTextCtrl" name="text_ti...
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxButton" name="button_su...
<label>ChangeTitle</label>
</object>
</object>
</object>
</object>
</resource>
>
The source code, sample_3_5.py, is shown below.
- sample_3_5.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_5.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.txt_title = xrc.XRCCTRL(self.frm_main, "tex...
self.btn_submit = xrc.XRCCTRL(self.frm_main, "bu...
self.btn_submit.Bind(wx.EVT_BUTTON, self.on_subm...
self.frm_main.SetTitle("sample_3_5")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
def on_submit(self, event):
self.frm_main.SetTitle(self.txt_title.GetValue())
self.txt_title.SetValue("")
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
The style of event processing is very similar to the samp...
** Changing the location of a Control [#g4df424b]
>
To use wxGade, the location of GUI parts is easily change...
>
>>
&ref(sample_3_6.png);
>
At ?wx.BoxSizer? the orientation is changed from HORIZON...
The location data (XRC file) of sample_3_6 is below.~
>
- sample_3_6.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Fri Nov 25 13:03:14 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<size>400, 300</size>
<title>main_frame</title>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<flag>wxALL|wxALIGN_CENTER_VERTICAL</flag>
<border>10</border>
<object class="wxTextCtrl" name="text_ti...
<size>200, 22</size>
</object>
</object>
<object class="sizeritem">
<flag>wxALL|wxALIGN_CENTER_VERTICAL</flag>
<border>10</border>
<object class="wxButton" name="button_su...
<label>ChangeTitle</label>
</object>
</object>
</object>
</object>
</resource>
>
The source code of sample_3_6.py is show below.~
>
- sample_3_6.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_6.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.txt_title = xrc.XRCCTRL(self.frm_main, "tex...
self.btn_submit = xrc.XRCCTRL(self.frm_main, "bu...
self.btn_submit.Bind(wx.EVT_BUTTON, self.on_subm...
self.frm_main.SetTitle("sample_3_6")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
def on_submit(self, event):
self.frm_main.SetTitle(self.txt_title.GetValue())
self.txt_title.SetValue("")
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
The names of the inputed XRC file and the initial title o...
>
To put apart the location information of GUI parts from t...
* Converting to exe file by py2exe [#g3804753]
** What is py2exe? [#rdf9aa11]
>
Up this section, this article has discussed how to create...
** Converting to executable file (.exe) [#h9d1fc48]
>
Let's convert sample_3_5 to the executable file. Create a...
- build.py
>
from distutils.core import setup
import py2exe
py2exe_options = {
"compressed": 1,
"optimize": 2,
"bundle_files": 2}
setup(
options = {"py2exe": py2exe_options},
windows = [
{"script" : "sample_3_5.py"}],
zipfile = None)
>
To execute py2exe, py2exe is treated as a parameter, and ...
- build.bat
>
build.py py2exe
copy .\msvcp90.dll .\dist\
copy .\sample_3_5.xrc .\dist\
move .\dist .\sample_3_5-bin
rmdir /s /q .\build
>
The source code file and XRC resource file of sample_3_5 ...
* Revision History [#n791fc54]
>>
- 2012/4/02 The article is initially uploaded.
End:
[[Software]]
* Introduction [#l2af1518]
** Overview [#d74d8005]
>
This article explains how to create GUI interface with Py...
** Targeted Audience [#a5101515]
>
The targeted audience of this article is expected to have...
** About wxPython [#q60e7beb]
>
wxPython is a GUI tool kit, which can work with Python. T...
* Using wxPython [#k5d37d57]
** Displaying window [#z0a5a518]
>
Let's start writing an application, which simply displays...
>
>>
&ref(sample_2_1.jpg);~
>
Its source code is shown below.
>
- sample_2_1.py
>>
import wx
class SampleApp(wx.App):
def OnInit(self):
self.init_frame()
return True
def init_frame(self):
self.frm_main = wx.Frame(None)
self.frm_main.SetTitle("Hello, wxPython!")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
sample_2_1.py is the basic and standard form of wxPython ...
First, ?SampleApp? class, which inherits ?wx.App,? is def...
** Placing Controls [#zb80bb62]
>
Let's put several Controls on the window.
>
>>
&ref(sample_2_2.jpg);~
>
The source code is show below.
- sample_2_2.py
>>
import wx
class SampleApp(wx.App):
def OnInit(self):
self.init_frame()
return True
def init_frame(self):
self.frm_main = wx.Frame(None)
self.sizer = wx.BoxSizer()
self.frm_main.SetSizer(self.sizer)
self.txt_title = wx.TextCtrl(self.frm_main)
self.sizer.Add(self.txt_title, 1, wx.ALIGN_CENTE...
self.btn_submit = wx.Button(self.frm_main)
self.btn_submit.SetLabel("Submit")
self.sizer.Add(self.btn_submit, 0, wx.ALIGN_CENT...
self.frm_main.SetTitle("sample_2_2")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
?wx.TextCtrl? and ?wx.Button? are placed in on the window...
>
>>
&ref(sample_2_2_sizer.jpg);~
** Processing events [#h300a60f]
>
Let's see how events are processed as controls are used. ...
>
>>
&ref(sample_2_3.jpg);~
>
The source code of sample_2_3 is shown below
- sample_2_3.py
>>
import wx
class SampleApp(wx.App):
def OnInit(self):
self.init_frame()
return True
def init_frame(self):
self.frm_main = wx.Frame(None)
self.sizer = wx.BoxSizer()
self.frm_main.SetSizer(self.sizer)
self.txt_title = wx.TextCtrl(self.frm_main)
self.sizer.Add(self.txt_title, 1, wx.ALIGN_CENTE...
self.btn_submit = wx.Button(self.frm_main)
self.btn_submit.SetLabel("Change Title")
self.btn_submit.Bind(wx.EVT_BUTTON, self.on_subm...
self.sizer.Add(self.btn_submit, 0, wx.ALIGN_CENT...
self.frm_main.SetTitle("sample_2_3")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
def on_submit(self, event):
self.frm_main.SetTitle(self.txt_title.GetValue())
self.txt_title.SetValue("")
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
The basic structure of this program is very similar to sa...
* Creating GUI with wxGlade [#r7ba8fef]
** what is wxGlade? [#ydb558f8]
>
In previous sections, xwPython enables to GUI programming...
>
wxGlade employs a simple drag-and-drop method, and GUI Co...
>
When GUI location data is output as a part of Python sour...
** How to use wxGlade [#j6cf106e]
>
wxGlade is consists of three windows. As booting wxGlade,...
>
- Main window
>>
&ref(wxglade_main.png);~
>
- Tree window
>>
&ref(wxglade_tree.png);~
>
- Porperty window
>>
&ref(wxglade_prop.png);~
>
In Main window, GUI parts, such as Frame and Control, are...
The details of how these windows work will be explained i...
** Displaying windows [#ea2e9cbf]
>
At the beginning, let's displays a simple window.
>
>>
&ref(sample_3_3.png);~
>
To execute this application, its appearance is almost ide...
>
To boot wxGlade, the basic information of configuration (...
- The output format is specified to the XRC format.
- At Encoding section, UTF-8 is selected.
- The output file is named.
>
>>
&ref(sample_3_3_property.png);~
>
As finishing the modification of the basic information, ...
>
>>
&ref(sample_3_3_select_frame_class.png);~
>
Then, ?frame_1? is added to Tree windows, and a new desig...
>
>>
&ref(sample_3_3_tree.png);~
>
To select ?frame_1? at Tree window, it allows editing Fra...
>
>>
&ref(sample_3_3_property_frame.png);~
>
This is an image as Design displays a window, which wxGla...
>
>>
&ref(sample_3_3_design.png);~
>
The window title and other specific configurations are re...
>
>>
&ref(sample_3_3_generate_code.png);
>
The output is shown below.
- sample_3_3.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Wed Nov 16 22:19:37 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<title>frame_main</title>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
</object>
</object>
</resource>
>
The source code, which enables sample_3.3 to create a win...
- sample_3.3.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_3.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.frm_main.SetTitle("sample_3_3")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
At the line of 8, ?xrc.XmlResource(XRC_FILE)? reads the X...
** Placing a Control [#m342633a]
>
Next, this shows how to place Controls. Put ?wx.TextCtrl?...
>
>>
&ref(sample_3_4.png);~
>
As explained in the previous sections, Controls need ?wx....
>
>>
&ref(sample_3_4_sizer.png);~
>
?Add a TextCtrl? is selected from Main window, and ?wx.Te...
>
>>
&ref(sample_3_4_design.png);~
>
To configure the name attribute of Control, output the so...
- sample_3_4.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Wed Nov 16 22:15:53 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<size>400, 300</size>
<title>main_frame</title>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxTextCtrl" name="text_in...
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxButton" name="button_su...
<label>Submit</label>
</object>
</object>
</object>
</object>
</resource>
>
The source code of displaying a window defines two tasks:...
- sample_3_4.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_4.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.txt_input = xrc.XRCCTRL(self.frm_main, "tex...
self.btn_submit = xrc.XRCCTRL(self.frm_main, "bu...
self.frm_main.SetTitle("sample_3_4")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
As the source code of sample_3_4 shows, an upside of usin...
** Event processing [#ddfea2a0]
>
Event processing is added to sample_3_4. The basic functi...
>
>>
&ref(sample_3_5.png);
>
Since there is no change in the locations of GUI parts, X...
- sample_3_5.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Wed Nov 16 22:16:28 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<size>400, 300</size>
<title>main_frame</title>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxTextCtrl" name="text_ti...
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_VERTICAL</flag>
<object class="wxButton" name="button_su...
<label>ChangeTitle</label>
</object>
</object>
</object>
</object>
</resource>
>
The source code, sample_3_5.py, is shown below.
- sample_3_5.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_5.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.txt_title = xrc.XRCCTRL(self.frm_main, "tex...
self.btn_submit = xrc.XRCCTRL(self.frm_main, "bu...
self.btn_submit.Bind(wx.EVT_BUTTON, self.on_subm...
self.frm_main.SetTitle("sample_3_5")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
def on_submit(self, event):
self.frm_main.SetTitle(self.txt_title.GetValue())
self.txt_title.SetValue("")
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
The style of event processing is very similar to the samp...
** Changing the location of a Control [#g4df424b]
>
To use wxGade, the location of GUI parts is easily change...
>
>>
&ref(sample_3_6.png);
>
At ?wx.BoxSizer? the orientation is changed from HORIZON...
The location data (XRC file) of sample_3_6 is below.~
>
- sample_3_6.xrc
>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by wxGlade 0.6.3 on Fri Nov 25 13:03:14 2...
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_main">
<style>wxDEFAULT_FRAME_STYLE</style>
<size>400, 300</size>
<title>main_frame</title>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<flag>wxALL|wxALIGN_CENTER_VERTICAL</flag>
<border>10</border>
<object class="wxTextCtrl" name="text_ti...
<size>200, 22</size>
</object>
</object>
<object class="sizeritem">
<flag>wxALL|wxALIGN_CENTER_VERTICAL</flag>
<border>10</border>
<object class="wxButton" name="button_su...
<label>ChangeTitle</label>
</object>
</object>
</object>
</object>
</resource>
>
The source code of sample_3_6.py is show below.~
>
- sample_3_6.py
>
import wx
from wx import xrc
XRC_FILE = "sample_3_6.xrc"
class SampleApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource(XRC_FILE)
self.init_frame()
return True
def init_frame(self):
self.frm_main = self.res.LoadFrame(None, "frame_...
self.txt_title = xrc.XRCCTRL(self.frm_main, "tex...
self.btn_submit = xrc.XRCCTRL(self.frm_main, "bu...
self.btn_submit.Bind(wx.EVT_BUTTON, self.on_subm...
self.frm_main.SetTitle("sample_3_6")
self.frm_main.SetSize((400, 200))
self.frm_main.Show()
def on_submit(self, event):
self.frm_main.SetTitle(self.txt_title.GetValue())
self.txt_title.SetValue("")
if __name__ == "__main__":
app = SampleApp(False)
app.MainLoop()
>
The names of the inputed XRC file and the initial title o...
>
To put apart the location information of GUI parts from t...
* Converting to exe file by py2exe [#g3804753]
** What is py2exe? [#rdf9aa11]
>
Up this section, this article has discussed how to create...
** Converting to executable file (.exe) [#h9d1fc48]
>
Let's convert sample_3_5 to the executable file. Create a...
- build.py
>
from distutils.core import setup
import py2exe
py2exe_options = {
"compressed": 1,
"optimize": 2,
"bundle_files": 2}
setup(
options = {"py2exe": py2exe_options},
windows = [
{"script" : "sample_3_5.py"}],
zipfile = None)
>
To execute py2exe, py2exe is treated as a parameter, and ...
- build.bat
>
build.py py2exe
copy .\msvcp90.dll .\dist\
copy .\sample_3_5.xrc .\dist\
move .\dist .\sample_3_5-bin
rmdir /s /q .\build
>
The source code file and XRC resource file of sample_3_5 ...
* Revision History [#n791fc54]
>>
- 2012/4/02 The article is initially uploaded.
Page: