1
wxpython有可能確定小部件如何接收其焦點? 即通過鼠標點擊或標籤鍵或箭頭鍵等 謝謝:)wxpython確定鼠標或按鍵是否觸發設定焦點事件
wxpython有可能確定小部件如何接收其焦點? 即通過鼠標點擊或標籤鍵或箭頭鍵等 謝謝:)wxpython確定鼠標或按鍵是否觸發設定焦點事件
我玩過這個,發現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()
出於好奇,爲什麼這很重要? – 2011-01-24 22:17:20