j.m.g.r
j.m.g.r

Reputation: 5489

Python - Move Turtle To Mouse On Click

I'd like to create a program where a turtle object moves to where a user clicks their mouse. I've been experimenting for a while, but I can't seem to get this to work.

from turtle import *
from time import sleep
turtle = Turtle()
screen = Screen()
while True:
    screen.onscreenclick(turtle.goto)
    sleep(0.1)

Upvotes: 1

Views: 4459

Answers (1)

turnt
turnt

Reputation: 3255

You don't need the while loop at all:

from turtle import *
from time import sleep
turtle = Turtle()
screen = Screen()
screen.onscreenclick(turtle.goto)
turtle.getscreen()._root.mainloop()

Upvotes: 2

Related Questions