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 Commented Dec 7, 2019 at 0:12
  • you could set player.speed(0) and it will move turtle at once - without animation. Commented Dec 7, 2019 at 1:15
  • How Do You Make Python Turtle Stop Moving? 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()
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.