获取鼠标移动中每个点的坐标

时间:2018-11-08 23:08:31

标签: python events tkinter

我需要 all 鼠标移动坐标:随着鼠标移动,我需要一个连续的(x,y)值序列。我当前的代码有空白:

def paint(self, event):
    self.line_width = self.choose_size_button.get()
    paint_color = 'white' if self.eraser_on else self.color

    coord = (event.x, event.y)
    if self.old_x == None or self.old_y == None:

    else:

        print(coord)
        paint_color = self.color
        self.c.create_line(self.old_x, self.old_y, event.x, event.y,
                                width=self.line_width, fill=paint_color,
                                capstyle=ROUND, smooth=TRUE, splinesteps=36)

coord是不完整的:它“跳跃”了一些点,可能是因为鼠标移动太快而失去了一些点。如何记录运输中的所有点?

1 个答案:

答案 0 :(得分:1)

您不能用比设备采样率更细的颗粒来记录输入。如果您已经为鼠标移动设置了细粒度的事件,那么在这方面,您最好的选择。

但是,如果由于某种原因需要连续点,您可以 内插缺失点以建立连接的路径。简单的方法是将点与Bresenham's line algorithm连接。我建议您使用一些平滑曲线。有几个软件包可以使一条曲线适合点序列;寻找术语“样条线”。

相关问题