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
       canvsasOne.update()

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

T

----- Original Message ----- From: "John Fouhy" <[EMAIL PROTECTED]>
To: "Teresa Stanton" <[EMAIL PROTECTED]>
Cc: <tutor@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 <[EMAIL PROTECTED]> 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.


"""
The purpose of this module is to build the maze and pathway that the '.gif's' follow. """
from Tkinter import *
import time

root = Tk()
root.title("Background")

canvasOne = Canvas(width = 800, height = 700, bg = 'black')
canvasOne.pack()

#This will build the north (top) wall of the maze
canvasOne.create_line(10, 10, 790, 10, width = 3, fill = 'blue') #west to east
canvasOne.create_line(20, 20, 395, 20, width = 3, fill = 'blue') #2nd line, 
west to middle
canvasOne.create_line(395, 20, 395, 100, width = 3, fill = 'blue') #middle to 
south
canvasOne.create_line(405, 20, 405, 100, width = 3, fill = 'blue')#2nd middle 
to south
canvasOne.create_line(395, 100, 405, 100, width = 3, fill = 'blue') #short west 
to east
canvasOne.create_line(405, 20, 780, 20, width = 3, fill = 'blue') #2nd line 
cont, middle to east

#This will build the left wall of the maze
canvasOne.create_line(10, 10, 10, 360, width = 3, fill = 'blue') #left North to 
South box
canvasOne.create_line(20, 20, 20, 350, width = 3, fill = 'blue') #left 2nd 
North to South box
canvasOne.create_line(20, 350, 160, 350, width = 3, fill = 'blue')#left indent 
west to east
canvasOne.create_line(10, 360, 150, 360, width = 3, fill = 'blue')#left 2nd 
west to east
canvasOne.create_line(160, 350, 160, 550, width = 3, fill = 'blue')#left indent 
north to south
canvasOne.create_line(150, 360, 150, 540, width = 3, fill = 'blue') #left 2nd 
north to south
canvasOne.create_line(150, 540, 10, 540, width = 3, fill = 'blue') #left indent 
east to west
canvasOne.create_line(160, 550, 20, 550, width = 3, fill = 'blue') #left 2nd 
east to west
canvasOne.create_line(10, 540, 10, 690, width = 3, fill = 'blue') #left indent 
to south wall
canvasOne.create_line(20, 550, 20, 680, width = 3, fill = 'blue') #left 2nd, 
box to south wall

#This will build the right wall of the maze
canvasOne.create_line(790, 10, 790, 360, width = 3, fill = 'blue') #right North 
to South box
canvasOne.create_line(780, 20, 780, 350, width = 3, fill = 'blue') #right 2nd 
North to South box
canvasOne.create_line(790, 360, 650, 360, width = 3, fill = 'blue')#right 
indent east to west
canvasOne.create_line(780, 350, 640, 350, width = 3, fill = 'blue')#right 2nd 
east to west
canvasOne.create_line(640, 350, 640, 550, width = 3, fill = 'blue')#right 
indent north to south
canvasOne.create_line(650, 360, 650, 540, width = 3, fill = 'blue') #right 2nd 
north to south
canvasOne.create_line(640, 550, 780, 550, width = 3, fill = 'blue') #right 
indent west to east
canvasOne.create_line(650, 540, 790, 540, width = 3, fill = 'blue') #right 2nd 
west to east
canvasOne.create_line(780, 550, 780, 680, width = 3, fill = 'blue') #right 
indent to south wall
canvasOne.create_line(790, 540, 790, 690, width = 3, fill = 'blue') #right 2nd, 
indent to south wall

#This will build the south (bottom) wall of the maze, and gate
canvasOne.create_line(10, 690, 325, 690, width = 3, fill = 'blue') #west to 
middle box
canvasOne.create_line(20, 680, 315, 680, width = 3, fill = 'blue') #2nd line, 
west to middle box
canvasOne.create_line(325, 690, 325, 650, width = 3, fill = 'blue') #middle to 
north
canvasOne.create_line(315, 680, 315, 640, width = 3, fill = 'blue')#2nd middle 
to north
canvasOne.create_line(315, 640, 350, 640, width = 3, fill = 'blue') #short west 
to middle wall
canvasOne.create_line(325, 650, 350, 650, width = 3, fill = 'blue') #2nd line 
cont, west to middle wall
canvasOne.create_line(350, 640, 350, 650, width = 3, fill = 'blue')# short 
closure left
canvasOne.create_line(350, 640, 450, 640, width = 3, fill = 'gold') # door
canvasOne.create_line(450, 640, 450, 650, width = 3, fill = 'blue') # short 
closure right
canvasOne.create_line(450, 640, 485, 640, width = 3, fill = 'blue') #short 
middle to east
canvasOne.create_line(450, 650, 475, 650, width = 3, fill = 'blue') # 2nd short 
middle to east
canvasOne.create_line(485, 640, 485, 680, width = 3, fill = 'blue') # gate to 
south wall
canvasOne.create_line(475, 650, 475, 690, width = 3, fill = 'blue') # 2nd gate 
to south wall
canvasOne.create_line(475, 690, 790, 690, width = 3, fill = 'blue') # wall, 
middle to east wall
canvasOne.create_line(485, 680, 780, 680, width = 3, fill = 'blue') # 2nd wall, 
middle to east wall
#this will add rectangles to the maze to give it the look of a path
#top left box
canvasOne.create_line(130, 105, 130, 125, width = 2, fill = 'blue') # upper 
left box left side
canvasOne.create_line(130, 125, 250, 125, width = 2, fill = 'blue') #upper left 
box bottom
canvasOne.create_line(130, 105, 250, 105, width = 2, fill = 'blue') # upper 
left box top
canvasOne.create_line(250, 105, 250, 125, width = 2, fill = 'blue') #upper left 
box right side

#second box top left
canvasOne.create_line(160, 215, 160, 225, width = 2, fill = 'blue') # second 
box left side
canvasOne.create_line(160, 215, 230, 215, width = 2, fill = 'blue')# second box 
bottom
canvasOne.create_line(160, 225, 230, 225, width = 2, fill = 'blue')# second box 
top
canvasOne.create_line(230, 215, 230, 225, width = 2, fill = 'blue')# second box 
right side

#top right box
canvasOne.create_line(545, 105, 545, 125, width = 2, fill = 'blue') # upper 
left box left side
canvasOne.create_line(545, 125, 665, 125, width = 2, fill = 'blue') #upper left 
box bottom
canvasOne.create_line(545, 105, 665, 105, width = 2, fill = 'blue') # upper 
left box top
canvasOne.create_line(665, 105, 665, 125, width = 2, fill = 'blue') #upper left 
box right side

#second box top right
canvasOne.create_line(560, 215, 560, 225, width = 2, fill = 'blue') # second 
box left side
canvasOne.create_line(560, 215, 625, 215, width = 2, fill = 'blue')# second box 
bottom
canvasOne.create_line(560, 225, 625, 225, width = 2, fill = 'blue')# second box 
top
canvasOne.create_line(625, 215, 625, 225, width = 2, fill = 'blue')# second box 
right side

#T shape middle
canvasOne.create_line(345, 210, 455, 210, width = 2, fill = 'blue')# top line 
of T
canvasOne.create_line(345, 210, 345, 220, width = 2, fill = 'blue')#left side
canvasOne.create_line(345, 220, 395, 220, width = 2, fill = 'blue')#bottom Left 
of T
canvasOne.create_line(395, 220, 395, 305, width = 2, fill = 'blue')#left 
vertical line of T
canvasOne.create_line(405, 220, 405, 305, width = 2, fill = 'blue')#right 
vertical line of T
canvasOne.create_line(395, 305, 405, 305, width = 2, fill = 'blue') #bottom cap 
of T
canvasOne.create_line(405, 220, 455, 220, width = 2, fill = 'blue') #bottom 
right of T
canvasOne.create_line(455, 210, 455, 220, width = 2, fill = 'blue') # right side

# Left sideways T
canvasOne.create_line(275, 340, 275, 500, width = 2, fill = 'blue') # left side 
of T
canvasOne.create_line(275, 340, 285, 340, width = 2, fill = 'blue') # top cap 
of T
canvasOne.create_line(285, 340, 285, 415, width = 2, fill = 'blue') # right 
side to middle of T
canvasOne.create_line(285, 415, 345, 415, width = 2, fill = 'blue') # top line 
of base of T
canvasOne.create_line(345, 415, 345, 425, width = 2, fill = 'blue') # end cap 
of base
canvasOne.create_line(285, 425, 345, 425, width = 2, fill = 'blue') # bottom 
line of base of T
canvasOne.create_line(285, 425, 285, 500, width = 2, fill = 'blue') # middle to 
bottom of T
canvasOne.create_line(275, 500, 285, 500, width = 2, fill = 'blue')

# Right sideways T
canvasOne.create_line(525, 340, 525, 500, width = 2, fill = 'blue') # right 
side of T
canvasOne.create_line(525, 340, 515, 340, width = 2, fill = 'blue') # top cap 
of T
canvasOne.create_line(515, 340, 515, 415, width = 2, fill = 'blue') # left side 
to middle of T
canvasOne.create_line(515, 415, 455, 415, width = 2, fill = 'blue') # top line 
of base of T
canvasOne.create_line(455, 415, 455, 425, width = 2, fill = 'blue') # end cap 
of base
canvasOne.create_line(515, 425, 455, 425, width = 2, fill = 'blue') # bottom 
line of base of T
canvasOne.create_line(515, 425, 515, 500, width = 2, fill = 'blue') # middle to 
bottom of T
canvasOne.create_line(515, 500, 525, 500, width = 2, fill = 'blue')

#This is the paths through the maze
#bottom left to middle
x = 40
for i in range(9):
   x += 20
   canvasOne.create_rectangle(x, 610, x+5, 615, fill = 'white')

#left path built north to south y = 290
for i in range(15):
   y += 20
   canvasOne.create_rectangle(220, y, 225, y+5, fill = 'white')

#left path above left indent
x = 60
for i in range(14):
   x +=20
   canvasOne.create_rectangle(x, 290, x+5, 295, fill = 'white')

#left path to top
y = 315
for i in range(13):
   y -= 20
   canvasOne.create_rectangle(60, y, 65, y-5, fill = 'white')

#top, west to middle indent
x = 60
for i in range(12):
   x += 20
   canvasOne.create_rectangle(x, 50, x+5, 55, fill = 'white')

#top indent to bottom of middle T
y = 50
for i in range(11):
   y += 20
   canvasOne.create_rectangle(300, y, 305, y+5, fill = 'white')

#top west to east above middle T and below top indent
x = 60
for i in range(33):
   x += 20
   canvasOne.create_rectangle(x, 170, x+5, 175, fill = 'white')

#top north to south, right ot top indent
y = 30
for i in range(13):
   y += 20
   canvasOne.create_rectangle(500, y, 505, y+5, fill = 'white')

#top indent to east
x = 500
for i in range(12):
   x += 20
   canvasOne.create_rectangle(x, 50, x+5, 55, fill = 'white')

#top right North to south
y = 30
for i in range(13):
   y +=20
   canvasOne.create_rectangle(740, y, 745, y+5, fill = 'white')

#middle T towards right wall
x = 440
for i in range(14):
   x += 20
   canvasOne.create_rectangle(x, 290, x+5, 295, fill = 'white')

#left of T North to South
y = 290
for i in range(4):
   y +=20
   canvasOne.create_rectangle(340, y, 345, y+5, fill = 'white')

#right of T North to South
y = 290
for i in range(4):
   y += 20
   canvasOne.create_rectangle(460, y, 465, y+5, fill = 'white')

#below T west to east
x = 340
for i in range(5):
   x += 20
   canvasOne.create_rectangle(x, 370, x+5, 375, fill = 'white')

#below T to gate North to South
y = 370
for i in range(10):
   y += 20
   canvasOne.create_rectangle(400, y, 405, y+5, fill = 'white')

#from West to East above gate
x = 220
for i in range(18):
   x += 20
   canvasOne.create_rectangle(x, 570, x+5, 575, fill = 'white')

#right side north to south right T
y = 290
for i in range(16):
   y += 20
   canvasOne.create_rectangle(580, y, 585, y+5, fill = 'white')

#right side gate to right wall
x = 580
for i in range(8):
   x += 20
   canvasOne.create_rectangle(x, 610, x+5, 615, fill = 'white')

#process image for use
image = "DustY1.gif"
photo = PhotoImage(file=image)
xp = 100
yp = 600
ph = canvasOne.create_image(xp,yp,image=photo)
ph
#direction will determine if the direction of the move is vertical or horizontal
def direction(event):
   if event.x <= xp+10 and event.x >= xp-10: #tolerance for inaccurate click
       newY = event.y
       onClickVertical(newY, xp, yp)
   if event.y <= yp+10 and event.y >= yp-10: #tolerance for inaccurate click
       newX = event.x
       onClickHorizontal(newX, xp, yp)

#onClick Vertical moves the .gif based on where the mouse is clicked
#newY is new location for yp
def onClickVertical(newY, xp, yp):
   print 'here'
   for i in range(newY):
       yp += .8
       canvasOne.coords(ph, xp, yp)
       time.sleep(.001)
       canvasOne.update()
   return xp, yp

#onClick Horizontal moves the .gif based on where the mouse is clicked
#newX is new location for xp
def onClickHorizontal(newX, xp, yp):
   for i in range(newX):
       xp += .8
       canvasOne.coords(ph, xp, yp)
       time.sleep(.001)
       canvasOne.update()
   return xp, yp

canvasOne.bind("<Button-1>", direction)

root.mainloop()

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to