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

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

2013-08-06 
为什么EVT_KILL_FOCUS处理函数没有被调用?程序如下,不管鼠标点击什么地方, OnKillFocus始终没有被调用. 不

为什么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

热点排行