need help to get my python image to move around using tkinter
twgrops at googlemail.com
twgrops at googlemail.com
Fri Nov 18 09:48:07 EST 2016
Hi I am new here and to python,
I am currently studying towards my degree in computer science and have to build a program but I have hit a brick wall. I am trying to make an image move around the canvas. I can make a rectangle move using the following:
#test rectangle
id1=canvas.create_rectangle(3,7,3+10,7+10)
# Generate x and y coordinates for 500 timesteps
for t in range(1, 500):
x1,y1,x2,y2=canvas.coords(id1)
# If a boundary has been crossed, reverse the direction
if x1 >= x_max:
vx = -10.0
if y1 <= y_min:
vy = 5.0
if y2 >= y_max:
vy = -5.0
if x1 <= x_min:
vx = 10.0
# Reposition the robot
canvas.coords(id1,x1+vx,y1+vy,x2+vx,y2+vy)
canvas.update()
# Pause for 0.1 seconds, then delete the image
time.sleep(0.1)
However i would like my image/sprite to move around:
objecttank=canvas.create_image(950,650,image=gif6, anchor= NW)
from what i gather it is because an image only has two axis, x and y but the rectangle seems to have 4 values, my error code keeps saying expecting 4 but got 2.
Can anyone help me in the right direction, many thanks tom.
More information about the Python-list
mailing list