Python - 使一个海龟对象总是在另一个之上 [英] Python - Make One Turtle Object Always Above Another

查看:29
本文介绍了Python - 使一个海龟对象总是在另一个之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个程序,其中一个 Turtle 对象始终位于所有其他 Turtle 对象之上.我不知道这是否可行,但任何帮助都会受到赞赏.

I would like to create a program where one Turtle object always stays above all of the other Turtle objects. I don't know if this is possible, but any help would be apprecated.

这是我的代码:

from turtle import *
while True:
    tri = Turtle()
    turtle = Turtle()
    tri.pu()
    tri.pencolor("white")
    tri.color("black")
    tri.shape("turtle")
    tri.bk(400)
    turtle = Turtle()
    turtle.pu()
    turtle.pencolor("white")
    turtle.shape("square")
    turtle.color("white")
    turtle.pu()
    turtle.speed(0)
    tri.speed(0)
    turtle.shapesize(100,100,00)
    setheading(towards(turtle))
    while tri.distance(turtle) > 10:
        turtle.ondrag(turtle.goto)
        tri.setheading(tri.towards(turtle))
        tri.fd(5)
    clearscreen()

推荐答案

为什么不先对底部"海龟进行所有绘制?然后画顶"乌龟?这应该使顶部的海龟始终可见.

Why not just do all the drawing for the "bottom" turtle first? Then do the drawing for the "top" turtle? This should make the top turtle always visible.

这篇关于Python - 使一个海龟对象总是在另一个之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆