使用 wxPython 用鼠标画一条连续的线

Drawing a Continuous Line with a Mouse with wxPython

我正在尝试在 wxPython 中创建一个 "whiteboard" 应用程序。我想弄清楚如何在用户单击时绘制一条跟随鼠标的线。

def __init__(self, parent):
    wx.Frame.__init__(self, parent, title="White Board")
    self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.OnDrag)

def OnDrag(self, e):
    print "drag"

第一步是尝试在用户拖动鼠标时获取鼠标坐标,但是无论我做什么我都无法打印 "drag" 这个词,我也不明白为什么不工作。

鼠标事件,wx.EVT_MOTION, will give you continuous updates as the mouse moves. Then determine whether the button is down, and also get the X and Y positions, using, say, wx.MouseState

wx.EVT_LIST_BEGIN_DRAG 不起作用,因为: 1) 它是一个列表控件事件; 2) 它仅在您开始拖动时触发,而不是整个时间。