调用函数时Python颜色填充不起作用

2024-04-25 00:19:27 发布

您现在位置:Python中文网/ 问答频道 /正文

可以帮助理解为什么我调用parralLogram函数时程序没有填充任何颜色。我在运行pythonv3。这是我的密码。在

    import turtle

    d_length = eval(input("Enter inside length of parallelogram: "))
    s = d_length / 2 * math.cos(math.pi / 4)
    parallelogramColor = turtle.fillcolor(" ")

    def parallelogram(s, parallelogramColor):
        for i in range(1):
            turtle.begin_fill()
            turtle.forward(s)
            turtle.left(45)
            turtle.forward(s)
            turtle.left(135)
            turtle.forward(s)
            turtle.left(45)
            turtle.forward(s)
            turtle.left(90)
            turtle.end_fill()

    parallelogram(s, "brown")

Tags: 函数import程序密码颜色mathleftfill
1条回答
网友
1楼 · 发布于 2024-04-25 00:19:27

^{}的文档显示

If turtleshape is a polygon, the interior of that polygon is drawn with the newly set fillcolor.

所以,海龟本身的颜色并不是它画的形状的颜色。在

请改用^{}。正如它的文件所说

Return or set pencolor and fillcolor

所以,你可以把你的函数改成

def parallelogram(s, parallelogramColor):
    turtle.color(parallelogramColor)

    turtle.color(parallelogramColor)
    turtle.begin_fill()
    turtle.forward(s)
    turtle.left(45)
    turtle.forward(s)
    turtle.left(135)
    turtle.forward(s)
    turtle.left(45)
    turtle.forward(s)
    turtle.left(90)
    turtle.end_fill()

您可以删除该循环,因为只有一个迭代。在

相关问题 更多 >