Q1: wxpython
中是否有鼠标单击事件。我没有找到单击事件。所以我使用Mouse_Down
和Mouse_UP
来实现这一点
Q2:我还有双击事件。但双击事件也可以上下移动鼠标。我如何区分它们?
答案 0 :(得分:3)
要区分点击和双击,您可以使用wx.Timer:
Similar discussion in Google Groups
代码示例(当然需要抛光和测试,但提供了基本想法):
import wx
TIMER_ID = 100
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(350,200))
self.timer = None
self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
def OnDoubleClick(self, event):
self.timer.Stop()
print("double click")
def OnSingleClick(self, event):
print("single click")
self.timer.Stop()
def OnLeftDown(self, event):
self.timer = wx.Timer(self, TIMER_ID)
self.timer.Start(200) # 0.2 seconds delay
wx.EVT_TIMER(self, TIMER_ID, self.OnSingleClick)
app = wx.App(redirect=True)
top = Frame("Hello World")
top.Show()
app.MainLoop()