【发布时间】:2020-08-03 20:21:55
【问题描述】:
有没有办法在 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')
【问题讨论】:
-
这有助于回答您的问题吗? stackoverflow.com/a/7811911/7432
-
将
output.coords(outputItem, x0, y0, e.x, e.y)更改为output.coords(outputItem, x0, y0, output.canvasx(e.x), output.canvasy(e.y))。
标签: python tkinter scrollbar draggable tkinter-canvas