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

Teresa Stanton tms43 at clearwire.net
Mon May 7 23:56:25 CEST 2007

Thank you, that was the correct direction.  What I ended up doing is this:

def onClickVertical(newY, xp, yp):
    for i in range(newY):  #nextX gives how many steps to the next position
        yp += .8                  #moves to correct position
        canvasOne.coords(ph, xp, yp)
        time.sleep(.001)     #creep along at a nice pace

It will move on the event, but then it moves back to the beginning and moves 
again after its been clicked.  I had posted in the Tkinter messageboard 
previously, but no one responded. I am thinking that one is .... dead (for 
lack of a better term).

I seem to be stuck again.  I've attached my entire file (and the .gif I'm 
using.  My son made this .gif, its our lab). The problem is my xp (the 
variable I use for my x coordinate) isn't updating after the .gif moves.  I 
think I should probably organize the entire module better, but then again, 
I've never written anything this big in Python, and nothing like this in 
Tkinter.  So, perhaps someone will have a suggestion?

Thank you


----- Original Message ----- 
From: "John Fouhy" <john at fouhy.net>
To: "Teresa Stanton" <tms43 at clearwire.net>
Cc: <tutor at python.org>
Sent: Thursday, May 03, 2007 4:36 PM
Subject: Re: [Tutor] canvas -> make an object 'seem' to move

> 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)
>    time.sleep(dur/step)
>    # you may need to add a call to canvas1.update_idletasks() here
> # untested
> HTH!
> -- 
> John.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: canvasBack.pyw
Url: http://mail.python.org/pipermail/tutor/attachments/20070507/4038f1f1/attachment-0001.asc 

More information about the Tutor mailing list