How to use <Button-4> & <Button-5> to zoom in and out the image in python
Finally I got the answer. Here is my code... I changed the above code as :
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()