有没有办法找出Tkinter中一个滚动条在画布上滚动了多少像素?我正在写一个应用程序,它可以拖放行。但是,每当我尝试拖动一行时,在滚动一定量之后,该行在滚动之前会自动以该行末尾所在的位置为中心。我的想法是将坐标偏移相同的量,以便在拖动时,线正好位于鼠标图标下方
#output is the canvas
#wires is a list containing the item ID's of all the lines in my project
def moveLine(e):
outputItem = output.find_withtag('current')
try:
x0, y0, x1, y1 = output.coords(outputItem)
except:
pass
if len(output.coords(outputItem)) != 0 and outputItem[0] in wires:
output.coords(outputItem, x0, y0, e.x, e.y)
output.itemconfig(outputItem, fill='blue')
有两种方法可以解决这个问题。你可以使用tkinter小部件滚动条,但移动图标将被延迟。第二种方法是制作你们自己的滚动条(点击事件,滑块的运动事件,别忘了阻止Y轴),并在这个运动事件上拖动图标和滑块。它会更平滑。如果你愿意,我可以给你发送自定义滚动条的代码
相关问题 更多 >
编程相关推荐