admin管理员组

文章数量:1570368

解决这类问题的方法是为屏幕上的每个固定标签指定一个海龟。这样,您就可以永久地将海龟定位在该位置,然后简单地执行undo()来清除旧文本,然后再write()来编写新的文本。在

下面是一个动态示例,您可以用鼠标在屏幕上拖动海龟,当前位置将写入屏幕中心:from turtle import Turtle, Screen

FONT = ('Arial', 24, 'normal')

playground = Screen()

playground.setup(500, 500)

playground.bgcolor("black")

runner = Turtle("triangle")

runner.color("white")

runner.speed("fastest")

runner.penup()

runner.setposition(200, 200)

marker = Turtle(visible=False) # our virtual magic marker

marker.penup()

marker.color("yellow")

marker.write(runner.position(), align='center', font=FONT) # so we can undo it

def drag_handler(x, y):

runner.ondrag(None) # disable handler while in handler

marker.undo() # erase previous position

marker.write((x, y), align='center', font=FONT)

runner.setheading(runner.towards(x, y)) # head towards new location

runner.setposition(x, y)

runner.ondrag(drag_handler)

runner.ondrag(drag_handler)

playground.mainloop()

本文标签: 坐标轴画布海龟坐标如何在