1)Pyton :The lastest version is 2.5
2)wxPython:The lastest version is wxPython2.8-win32-unicode-2.8.9.1-py25.exe
3)A favorate text editor,or a IDE like eclipe:I like to use Eclipse with PyDev plugin,it's really helpful.
Or now let's start our first step.I'll provide a very simple example.
#code begin-------------
import wx
class MyApp(wx.App):
def OnInit(self):
frame=wx.Frame(parent=None,title="Simple Window")
frame.Show()
return True
app=MyApp()
app.MainLoop()
#code end---------------
Then run command
->>python simple.py
You will see a very simple blank frame,with a title string "hello world".The real purpose of this program is to make sure you can create a Python source file, verify that wxPython is installed properly, and allow us to introduce more complex aspects of wxPython programming one step at a time.
OK,Now let examine this simple program step-by-step"
1)The first thing we need to do is import necessary library,it's the main wxPython package,which is named wx:
import wx
Once the package is imported,then we can refer to wxPython class,functions etc.
2)Now it's time to create our new App.every wxPython program must have one object and at least one Application,so we need to subclass wx.App class.
class MyApp(wx.App):
Then we need to extend the OnInit() method of parent class,then it's will be call when applicaiton run.
def OnInit(self):
frame=wx.Frame(parent=None,title="Simple Window")
frame.Show()
return True
As you can see we define the tile of Frame with string "Simple Window"and we invoke the method frame.Show(),it let Frame show,although we create a Frame object,but if we don't invoke the method show().we'll never see it.
3)The final step is to create an instance of the wx.App subclass, and invoke its Main-Loop() method:
app = App()
app.MainLoop()

No comments:
Post a Comment