1.按钮
①普通按钮,原来实现事件的简单处理
a)声明如下
#普通按钮,左边添加静态文本信息
wx.StaticText(parent=self.panel,label='Generally-Button:',pos=(20,20))
self.gButton=wx.Button(parent=self.panel,label='generally',pos=(150,20))
b)为按钮绑定处理函数
#为普通按钮绑定方法
self.Bind(wx.EVT_BUTTON,self.OngButton,self.gButton)
c)处理函数的实现
#绑定函数
def OngButton(self,event):
dlg=wx.MessageDialog(self,'Really Quit','Caution',style=wx.CANCEL|wx.OK|wx.ICON_QUESTION)
if dlg.ShowModal()==wx.ID_OK:
dlg.Destroy()
d)运行结果
②单选按钮,用来实现对象的选择
a)声明格式
#单选按钮
wx.StaticText(parent=self.panel,label='RadioButton:',pos=(20,110))
self.radioButtonsexM=wx.RadioButton(self.panel,-1,'Male',pos=(150,100))
self.radioButtonsexW=wx.RadioButton(self.panel,-1,'Femal',pos=(150,120))
b)运行结果
2.复选框
①声明格式和绑定函数
#复选按钮
wx.StaticText(parent=self.panel,label='CheckBox',pos=(20,200))
self.checkButton=wx.CheckBox(self.panel,-1,'Administrator',pos=(150,200))
②运行结果
3.组合框
①声明格式和绑定函数
#组合框
#设置组合框的值
self.address={
'first':['CQ','BJ','SH','SC'],'second':['HC','GZ','XJ','XZ']}
#声名复合框
self.comBox1=wx.ComboBox(self.panel,value='Address',choices=list(self.address.keys()),pos=(300,20),size=(100,30))
self.Bind(wx.EVT_COMBOBOX,self.OnCombox1,self.comBox1)
self.comBox2=wx.ComboBox(self.panel,value='City',choices=[],pos=(300,50),size=(100,30))
self.Bind(wx.EVT_COMBOBOX,self.OnCombox2,self.comBox2)
②绑定函数实现
#组合框操作
def OnCombox1(self,event):
banji=self.comBox1.GetValue()
self.comBox2.Set(self.address[banji