Python - 单击鼠标移动鼠标

时间:2014-03-02 22:17:21

标签: python turtle-graphics

我想创建一个程序,其中龟对象移动到用户单击鼠标的位置。我已经尝试了一段时间,但我似乎无法让它发挥作用。

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

1 个答案:

答案 0 :(得分:2)

根本不需要while循环:

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