wxpython event事件_wxpython event.Skip()

# -.- coding:utf-8 -.-

import wx

class MyFrame(wx.Frame):

# 原意

# event.Skip() can be used inside an event handler to control

# whether further event handlers bound to this event will be

# called after the current one returns.

# 翻译:

# event.Skip() 函数 只能在 绑定了事件的函数中 使用; 例如:

# self.Third 绑定了 menuTwice 事件, 因此 self.Second 函数可以使用 event.Skip() 方法.

#

# 对于那些被多个函数绑定的事件, event.Skip() 可以在

# 执行完当前函数后继续去执行其他绑定到该事件的函数; 例如:

# menuTwice 被 self.First 和 self.Second 和 self.Third 函数 都绑定了,

# 触发 menuTwice 事件时, wxpython 只会执行 self.Third 函数,

# 因为 self.First 和 self.Second 都被 self.Third "覆盖" 了.

# 但是如果在 self.Third 中使用 event.Skip() , 那么wxpython 会在执行完

# self.Third 函数后, 继续去执行 self.Second 函数;

# 如果在 self.Second 中还调用 event.Skip(), 那么 wxpython 会在执行完

# self.Second 函数后, 继续去执行 self.First 函数.

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)

# 这里的 menuTwice 菜单被三个函数绑定.

self.Bind(wx.EVT_MENU, self.First, menuTwice)

self.Bind(wx.EVT_MENU, self.Second, menuTwice)

self.Bind(wx.EVT_MENU, self.Third, menuTwice)

self.SetMenuBar(menuBar)

self.Show(True)

def First(self, event):

print "First"

def Second(self, event):

print "Second"

event.Skip()

def Third(self, event):

print("Third")

event.Skip()

print("Third2") # 执行完当前函数后才会去执行 self.Second.

app = wx.App(False)

frame = MyFrame(None, 'Small editor')

app.MainLoop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值