首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

四.事件处理

2013-11-22 
4.事件处理对事件的反应在wxPython是称为事件处理。一个事件是当“东西”发生在您的应用程序(单击按钮、文本输

4.事件处理
对事件的反应在wxPython是称为事件处理。一个事件是当“东西”发生在您的应用程序(单击按钮、文本输入、鼠标移动等)。大部分的GUI编程由响应事件。你在绑定对象到事件使用bind()方法:


This means that, from now on, when the user selects the "About" menu item, the method self.OnAbout will be executed. wx.EVT_MENU is the "select menu item" event. wxWidgets understands many other events (see the full list). The self.OnAbout method has the general declaration:

这是说,从现在开始,当用户选择了"About"按钮,self.OnAbout方法被执行。wx.EVT_MENU代表“选择按钮”事件。wxWidgets明白很多事件处理。

这个方法用下边的形式表现:

 

'''Created on 2012-6-29@author: Administrator'''import wxclass MyFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self,parent,title=title,size=(500,250)) self.contrl = wx.TextCtrl(self,style=wx.TE_MULTILINE) self.CreateStatusBar() filemenu = wx.Menu() menuAbout=filemenu.Append(wx.ID_ABOUT,"&About","about this program") filemenu.AppendSeparator() menuExit=filemenu.Append(wx.ID_EXIT,"E&xit","Close program") menuBar = wx.MenuBar() menuBar.Append(filemenu,"&File") self.Bind(wx.EVT_MENU, self.OnAbout,menuAbout) self.Bind(wx.EVT_MENU, self.OnExit,menuExit) self.SetMenuBar(menuBar) self.Show(True) def OnAbout(self,e): dlg = wx.MessageDialog(self,"A small editor","about simple editor",wx.OK) dlg.ShowModal() dlg.Destroy() def OnExit(self,e): self.Close(True)app = wx.App(False)frame = MyFrame(None,"Small Editor")app.MainLoop()


 

热点排行