你可以在wxPython示例和帮助里发现完整的控件组件,这里只是列举一常最常用到的:
wxButton一个按钮:显示一个文本,你可以点击。举例来说,这里是一个“清理”按钮(如清理一个文本):
clearButton = wx.Button(self, wx.ID_CLEAR, "Clear") self.Bind(wx.EVT_BUTTON, self.OnClear, clearButton)
textField = wx.TextCtrl(self) self.Bind(wx.EVT_TEXT, self.OnChange, textField) self.Bind(wx.EVT_CHAR, self.OnKeyPress, textField)如果用户按下“Clear”按钮,就会调用 EVT_TEXT事件,却不会调用EVT_CHAR
wxComboBox组合框:非常类似于wxTextCtrl,但所产生的wxTextCtrl除了事件,wxComboBox有EVT_COMBOBOX事件。
wxCheckBox复选框:让用户选择true / false。
wxRadioBox选项列表
我们仔细这个例子:
''' Created on 2012-6-30 @author: Administrator ''' import wx class ExamplePanel(wx.Panel): def __init__(self,parent): wx.Panel.__init__(self,parent) self.quote = wx.StaticText(self,label="Your quote:",pos=(20,30)) self.logger = wx.TextCtrl(self,pos=(300,20),size=(200,300),style=wx.TE_MULTILINE|wx.TE_READONLY) self.button = wx.Button(self,label="Save",pos=(200,325)) self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) self.lblname = wx.StaticText(self,label="Your name:",pos=(20,60)) self.editname = wx.TextCtrl(self,value="Enter your name",pos=(150,60),size=(140,-1)) self.Bind(wx.EVT_TEXT, self.EvtText, self.editname) self.Bind(wx.EVT_CHAR, self.EvtChar, self.editname) self.sampleList = ['frients','advertising','web search','Yellow pages'] self.lblhear = wx.StaticText(self,label="How did you hear fraom us?",pos=(20,90)) self.edithear = wx.ComboBox(self,pos=(150,110),size=(95,-1),choices=self.sampleList,style=wx.CB_DROPDOWN) self.Bind(wx.EVT_COMBOBOX, self.EvtCombobox, self.edithear) self.Bind(wx.EVT_TEXT, self.EvtText, self.edithear) self.insure = wx.CheckBox(self,label="Do you want Insured shipment?",pos=(20,180)) self.Bind(wx.EVT_CHECKBOX, self.EvtCheckbox, self.insure) radioList = ['blue','red','yellow','orange','green','purple','navy blue','black','gray'] rb = wx.RadioBox(self,label="what color do you like?",pos=(20,210),choices=radioList, majorDimension=3,style=wx.RA_SPECIFY_COLS) self.Bind(wx.EVT_RADIOBOX, self.EvtRadiobox, rb) def OnClick(self,e): self.logger.AppendText("Click on object with Id %d\n" % e.GetId()) def EvtText(self,e): self.logger.AppendText("EvtText:%s\n" % e.GetString()) def EvtChar(self,e): self.logger.AppendText("EvtChar:%d\n" % e.GetKeyCode()) e.Skip() def EvtCombobox(self,e): self.logger.AppendText("EvtCombox:%s\n" % e.GetString()) def EvtCheckbox(self,e): self.logger.AppendText("EvtCheckBox:%d\n" % e.Checked()) def EvtRadiobox(self,e): self.logger.AppendText("EvtRadiobox:%d\n" % e.GetInt()) app = wx.App(False) frame = wx.Frame(None) panel = ExamplePanel(frame) frame.Show() app.MainLoop()