[wxPython] event.Skip()的用法
2016-07-03 16:28
441 查看
wxPython笔记 - event.Skip()的用法
在wxPyWiki上学wxPython时,看到event.Skip()有点不能理解,使用过后发现其特性对于理解wxPython的多事件触发过程有所帮助,便记录下来。以下是基于事件绑定前做的demo的修改,主要结构是”Test”菜单中的两个按钮分别绑定了一个和两个事件,这两个事件都是在控制台里输出不同的东西。
import wx class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self,parent,title=title, size=(400,500)) self.control = wx.TextCtrl(self, style = wx.TE_MULTILINE) self.CreateStatusBar() #the status bar in the bottom menuBar = wx.MenuBar() testMenu = wx.Menu() menuOnce = testMenu.Append(wx.ID_ANY, "Once", "print something") menuTwice = testMenu.Append(wx.ID_ANY, "Twice", "print something and another thing") menuBar.Append(testMenu, "Test") self.Bind(wx.EVT_MENU, self.First, menuOnce) self.Bind(wx.EVT_MENU, self.First, menuTwice) self.Bind(wx.EVT_MENU, self.Second, menuTwice) self.SetMenuBar(menuBar) self.Show(True) def First(self, event): print "something" def Second(self, event): print "another thing" app = wx.App(False) #what does False mean? frame = MyFrame(None, 'Small editor') app.MainLoop()
如果直接这么运行,点击”twice”时,会发生只有Second()响应的情况,说明对菜单点击这个事件的处理只到Second()结束为止。因此,想要让First()和Second()都响应”twice”,那么需要在Second()中最后加上event.Skip()。
另外,根据这个demo也可以发现,绑定在同一个事件上的不同函数,其执行的顺序是从下往上,也就是后绑定的先运行。
相关文章推荐
- windows环境下安装Python Django
- Python 数据分析包:pandas 基础
- Windows Server使用python实现自动化运维——开启系统更新服务
- python切片的使用
- python challenge 学习
- Reverse Integer (python)
- python
- python - socket练习(输入系统命令)
- python发送邮件
- 详解 jupyter notebook 集成 spark 环境安装
- 使用Python从有道词典网页获取单词翻译
- sudo apt-get install python-pip 失败
- PyMol - script
- Python - 列表与字典相互转换
- Python - 统计MAC地址
- Python知识点整理(异常篇)
- Python - 统计系统内存练习
- Python - if语句控制
- Python-使用for循环遍历文件
- Python - while循环