[Tutor] canvas -> make an object 'seem' to move
Teresa Stanton
tms43 at clearwire.net
Fri May 4 00:15:02 CEST 2007
Hi all:
I am working on a program that will take a .gif and move it from origin, along a path where the mouse clicks. I understand that the move is simply changing the coordinates. I can place several .gif's on the canvas, but I would like to make the previous image go away (delete or be removed) and thus far been unable to do that. The example program I wrote simply takes 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. And when I try to use delete, well, it doesn't work, I get an error message. I should mention that I'm using python25.
Here is my rather early example code:
from Tkinter import *
root = Tk()
root.title("Click me!")
def next_image(event):
global x, y, photo
photoId = canvas1.create_image(x, y, image=photo)
# I realize this isn't the best way to do it, but until I get something working...
canvas1.create_image(x+10, y, image=photo) # this seems more successful, but the image remains
canvas1.create_image(x+20, y, image=photo) # after I click. I don't want the image to remain,
canvas1.create_image(x+30, y, image=photo) # I actually want to see a slow deliberate movement
canvas1.create_image(x+40, y, image=photo) # to the final spot.
canvas1.create_image(x+50, y, image=photo)
canvas1.create_image(x+60, y, image=photo)
canvas1.create_image(x+70, y, image=photo)
#canvas1.move(, 100, 0)
image = "DustY1.GIF" # use any gif, this is a cartoon of my dog
photo = PhotoImage(file=image)
# make canvas the size of image1/photo1
width1 = photo.width()
height1 = photo.height()
canvas1 = Canvas(width=width1, height=height1)
canvas1.pack()
# display photo, x, y is center
x = (width1)/2.0
y = (height1)/2.0
# this is the first image
canvas1.create_image(x, y, image=photo)
canvas1.bind('<Button-1>', next_image) # bind left mouse click
root.mainloop()
Thank you for your help!
T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070503/4f3abb4e/attachment.htm
More information about the Tutor
mailing list