def onWheel(event):
d = event.delta
if d < 0:
amt=0.9
else:
amt=1.1
canvas.scale(ALL, 200,200 , amt, amt)
canvas.bind("<Button-4>&<Button-5>", onWheel)
canvas.focus_set()这是我的代码。我在ubuntu机器的tkinter窗口中运行它。但我只能放大图像。缩小不起作用。我想使用button-4和button-5来放大和缩小图像
发布于 2015-07-03 16:45:37
我终于得到了答案。这是我的代码。我将上面的代码修改为:
from Tkinter import *
root = Tk()
Label(root, text='Zoom in & Zoom out using the Mouse Wheel' ,font('Times',12)).pack()
canvas = Canvas(root, width=400, height=400)
canvas.pack(fill=BOTH, expand=1)
canvas.create_rectangle(175,175,225,225,fill='blue')
def zoomin(event):
d = event.delta
if d < 0:
amt=0.9
else:
amt=1.1
canvas.scale(ALL, 200,200 , amt,amt)
canvas.bind("<Button-4>", zoomin)
def zoomout(event):
d = event.delta
if d >0:
amt=1.1
else:
amt=0.9
canvas.scale(ALL, 200,200 , amt, amt)
canvas.bind("<Button-5>", zoomout)
canvas.focus_set()
root.mainloop()https://stackoverflow.com/questions/31199130
复制相似问题