wxpython,一对一,事件源、事件类型、事件处理
import wx
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None,title="yiduiyi",size=(300,400),pos=(100,100))
self.Center()
panel = wx.Panel(parent=self)
self.statictext = wx.StaticText(parent=panel,pos=(100,10))
b=wx.Button(parent=panel,label='OK',pos=(10,10))
self.Bind(wx.EVT_BUTTON,self.on_click,b) #wx.EVT_BUTTON是按钮单击事件类型,self.on_click是事件处理,b是事件源
def on_click(self,event):
print(event)
self.statictext.SetLabel("shanghai_life")
class App(wx.App):
def OnInit(self):
frame = MyFrame()
frame.Show()
return True
def OnExit(self):
print("tuichu")
return 0
if __name__ == '__main__':
app=App()
app.MainLoop()