读书人

为何EVT_KILL_FOCUS处理函数没有被调用

发布时间: 2013-08-06 16:47:25 作者: rapoo

为什么EVT_KILL_FOCUS处理函数没有被调用?
程序如下,不管鼠标点击什么地方, OnKillFocus始终没有被调用. 不知道什么原因? 难道button压根就没有获得过焦点, 就无所谓失去焦点?
import wx

class ExampleFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
panel = wx.Panel(self)

#A button
self.button = wx.Button(panel, label="Button", pos=(20, 60))

self.button2 = wx.Button(panel, label="Button2", pos=(200, 60))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)

self.button.SetFocus()

self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus, self.button)

self.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus, self.button)

self.Show()

def OnClick(self, evt):
print "button clicked"

def OnKillFocus(self, evt):
print "button lose focus"

def OnGetFocus(self, evt):
print "button get focus"

if __name__ == '__main__':
app = wx.App(False)
frame = ExampleFrame(None)
app.MainLoop()
[解决办法]
貌似非CommandEvent,要如下写法:
self.button.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)


self.button.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)

参考:http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind

读书人网 >perl python

热点推荐