wxPython事件处理
来源:互联网 发布:甬温动车事故 知乎 编辑:程序博客网 时间:2024/06/02 10:42
对事件的反应在wxPython是称为事件处理。一个事件是当“东西”发生在您的应用程序(单击按钮、文本输入、鼠标移动等)。大部分的GUI编程由响应事件。你在绑定对象到事件使用bind()方法:
- class MainWindow(wx.Frame):
- def __init__(self, parent, title):
- wx.Frame.__init__(self,parent, title=title, size=(200,100))
- ...
- menuItem = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
- self.Bind(wx.EVT_MENU, self.OnAbout, menuItem)
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明白很多事件处理。
这个方法用下边的形式表现:
- def OnAbout(self, event):
- ...
- <span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">这里的event是wx.Event的实例。比如一个按钮单击事件-wx.EVT-BUTTON就是一个wx.Event的实例。</span>
- def OnButtonClick(self, event):
- if (some_condition):
- do_something()
- else:
- event.Skip()
- def OnEvent(self, event):
当一个button-click事件发生时,该方法将被调用OnButtonClick。如果some_condition是真的,我们do_something()否则我们让事件处理的更普遍的事件处理程序。现在让我们看看我们的应用程序:
- '''''
- Created on 2012-6-29
- @author: Administrator
- '''
- import wx
- class 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()
- wxPython的事件处理
- wxPython事件处理
- wxPython事件处理
- wxPython:事件处理介绍一
- wxPython:事件处理介绍二
- wxPython的事件处理过程详解
- 给wxPython事件处理函数传递参数
- wxPython事件
- wxPython事件
- wxpython事件
- wxPython之响应事件
- wxPython中自定义事件
- wxPython 事件驱动
- wxpython 事件驱动
- wxpython 自定义事件
- wxpython的事件列表
- wxpython 监听Activex事件
- wxpython常见事件
- wxPython构建一个简单的文本编辑器
- Ubuntu 网易更新源地址
- 水果忍者(二)
- 关键词加密
- SSH整合
- wxPython事件处理
- jsp中EL表达式的用法
- wxPython添加菜单
- NASM笔记
- Eclipse复制粘贴卡机的问题解决方法
- 他们可以偷走你的创意,但他们偷走不了你。他们偷走不了你的风格,你的创造力,以及你成功的动力——这才是使你的事业与众不同的地方
- Date类和Calendar类的使用
- 解决eclipse中overlaps the location of another project: 'xxxx'
- jQuery - slider 控件的简单使用(一)