0

How do I make it so that the goto used previously stops executing when I try to execute another? Whenever I click before the turtle stops moving, the turtle will move to the position I want it to but then resume its previous goto commands. Is there a solution to this?

player = turtle.Turtle()
player.speed(1)
def moveturtle(x,y):
    player.goto(x,y)

scrn = turtle.Screen()
scrn.delay(50)
player.penup()
scrn.onscreenclick(moveturtle)

scrn.listen()
scrn.mainloop()

https://i.gyazo.com/307b25676791055f9ace9a08f680437c.mp4

4
  • "Whenever I click before the turtle stops moving, the turtle will move to the position I want it to but then resume its previous goto commands." Can you provide more detail about this? For example, you click at a position and it starts to move. Then do you click again at another position before it reached the first position? Does the turtle start moving to the second position immediately? Or does it finish going to the first position before moving to the second? If you know how to make an animated GIF, that could help show what you are trying to explain as well. Commented Dec 7, 2019 at 0:04
  • added video of problem
    – crayolas
    Commented Dec 7, 2019 at 0:12
  • you could set player.speed(0) and it will move turtle at once - without animation.
    – furas
    Commented Dec 7, 2019 at 1:15
  • How Do You Make Python Turtle Stop Moving?
    – furas
    Commented Dec 7, 2019 at 1:17

1 Answer 1

1

I guess there is not a way to get it the way I intended it to be. I wanted the user to be able to change the path of the turtle at any time, but instead, I had to make it so that the turtle must complete its previous path before being assigned a new one.

player = turtle.Turtle()
pos1 = player.position()
player.speed(1)
def moveturtle(x,y):
    nonlocal pos1
    if player.distance(pos1) == 0:
        player.goto(x,y)
        pos1 = (x,y)

scrn = turtle.Screen()
scrn.delay(50)
player.penup()
scrn.onscreenclick(moveturtle)

scrn.listen()
scrn.mainloop()
1
  • Another solution is instead of moving directly to the clicked position, move in the same direction but in shorter increments. Then when the user clicks again, you can stop moving after the most recent increment and then move in the new direction. Commented Dec 9, 2019 at 16:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.