如何更改乌龟的颜色,而不是笔的颜色?

时间:2020-04-28 00:34:52

标签: python python-3.x turtle-graphics python-turtle

您如何更改龟的颜色,而不是笔的颜色?我希望乌龟在屏幕上绘制白色,但是如果我将颜色更改为“白色”,我将无法再看到乌龟。是否有类似turtle.turtlecolor之类的东西?

2 个答案:

答案 0 :(得分:4)

我们可以使用用户光标定义功能将光标的颜色(轮廓和填充)与光标绘制的颜色(轮廓和填充)断开连接:

from turtle import Screen, Shape, Turtle

screen = Screen()
screen.bgcolor('black')

turtle = Turtle()
turtle.shape("turtle")
polygon = turtle.get_shapepoly()

fixed_color_turtle = Shape("compound")
fixed_color_turtle.addcomponent(polygon, "orange", "blue")

screen.register_shape('fixed', fixed_color_turtle)

turtle.shape('fixed')
turtle.color('white')
turtle.circle(150)

screen.exitonclick()

此乌龟光标为橙色,带有蓝色轮廓,但绘制了一条白线:

enter image description here

答案 1 :(得分:1)

肯定有!

turtle.shape("turtle")
turtle.fillcolor("red")

现在,您会得到一只红海龟。