[Tutor] canvas -> make an object 'seem' to move

John Fouhy john at fouhy.net
Fri May 4 01:36:22 CEST 2007

On 04/05/07, Teresa Stanton <tms43 at clearwire.net> wrote:
> the image and moves it.  I should mention that I've tried 'move() and
> coord()' to get the object to move, but I am not getting the effect I want.
> When I use move in successive steps it just appears at the last move
> coordinates.

My Tkinter is quite rusty, but I think this is basically the approach
you need to take.  However, you will need to put a delay in between
each call to coords, otherwise python will "optimise" by moving the
image to its final destination before drawing.

Something like:

# given initial coords (x0,y0), final coords (x1, y1)
img = canvas1.create_image(x0, y0, image=photo)

# step: number of steps to move in
step = 10.0
# duration: number of seconds to move the image
dur = 2

for i in range(1, int(step)+1):
    xi = x0 + i*(x1-x0)/step
    yi = y0 + i*(y1-y0)/step
    canvas1.coords(img, xi, yi)
    # you may need to add a call to canvas1.update_idletasks() here

# untested



More information about the Tutor mailing list