2011-01-24 49 views

回答

0

我玩過這個,發現EVT_SET_FOCUS只攜帶有關窗口的信息剩下。所以你真的想綁定EVT_LEFT_DOWN。

import wx 

class MainWindow(wx.Frame): 
    def __init__(self, *args, **kwargs): 
     wx.Frame.__init__(self, *args, **kwargs) 
     self.last_was_mouse = False 

     self.panel = wx.Panel(self) 
     self.button = wx.Button(self.panel, label="Test") 
     self.button2 = wx.Button(self.panel, label="Test") 
     self.sizer = wx.BoxSizer() 
     self.sizer.Add(self.button) 
     self.sizer.Add(self.button2) 
     self.panel.SetSizerAndFit(self.sizer) 
     self.Show() 

     self.button2.Bind(wx.EVT_SET_FOCUS, self.OnFocus) 
     self.button2.Bind(wx.EVT_LEFT_DOWN, self.OnMouse) 


    def OnFocus(self, e): 
     if self.last_was_mouse: 
      print "Focus by mouse" 
     else: 
      print "Focus by keyboard" 
     self.last_was_mouse = False 

    def OnMouse(self, e): 
     self.last_was_mouse = True 
     e.Skip() 

app = wx.App(False) 
win = MainWindow(None) 
app.MainLoop() 
相關問題