admin管理员组文章数量:1570411
解决这类问题的方法是为屏幕上的每个固定标签指定一个海龟。这样,您就可以永久地将海龟定位在该位置,然后简单地执行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()
版权声明:本文标题:python turtle显示坐标轴_如何在画布上显示海龟坐标 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727669135a1124974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论