Move a tkinter canvas with Mouse

Viewed 11585

I would like to move a whole tkinter Canvas with Mouse Click (hold) + Motion of the mouse. I tried with canvas.move but it doesn't work unfortunately.

How can I scroll in the whole canvas ? (not move each element of the canvas, but rather scroll the displayed area of the canvas)

import Tkinter as Tk

oldx = 0
oldy = 0

def oldxyset(event):
    global oldx, oldy
    oldx = event.x
    oldy = event.y

def callback(event):
    # How to move the whole canvas here?
    print oldx - event.x, oldy - event.y

root = Tk.Tk()

c = Tk.Canvas(root, width=400, height=400, bg='white')
o = c.create_oval(150, 10, 100, 60, fill='red')
c.pack()

c.bind("<ButtonPress-1>", oldxyset)
c.bind("<B1-Motion>", callback)

root.mainloop()
1 Answers
Related