我正在尝试使用 tkinter 和 python 使方形对齐网格并且它正在工作。问题是我在画布上添加了缩放功能,缩放后快照不起作用......
对于缩放,我这样做:
def do_zoom(event):
global x, y, fac
x, y= canvas.canvasx(event.x), canvas.canvasy(event.y)
factor = 1.001 ** event.delta
canvas.scale(ALL, x, y, factor, factor)
canvas.bind("<MouseWheel>", do_zoom)
canvas.bind('<ButtonPress-1>', lambda event: canvas.scan_mark(event.x, event.y))
canvas.bind("<B1-Motion>", lambda event: canvas.scan_dragto(event.x, event.y, gain=1))
而对于形状我做的快照“光标”:
def cursor_move(event):
xg = (canvas.canvasx(event.x))//10 #10 is espace between each grid square
yg = (canvas.canvasy(event.y))//10
cursor = canvas.find_withtag('cursor')
canvas.moveto(cursor, xg*10, yg*10)
它在我不缩放时工作,但是当我缩放时,“光标”很古怪......代码中的 10 是每个网格正方形之间的空间,所以我可能需要更改它,但我找不到 calcul 做什么。谢谢你的帮助!