Tkinter画布拖离中心

2024-05-14 17:17:05 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法找出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')

Tags: thein应用程序outputistkinter画布像素
1条回答
网友
1楼 · 发布于 2024-05-14 17:17:05

有两种方法可以解决这个问题。你可以使用tkinter小部件滚动条,但移动图标将被延迟。第二种方法是制作你们自己的滚动条(点击事件,滑块的运动事件,别忘了阻止Y轴),并在这个运动事件上拖动图标和滑块。它会更平滑。如果你愿意,我可以给你发送自定义滚动条的代码

相关问题 更多 >

    热门问题