我找不到我的代码哪里出错了,我正在尝试所有的方法:(
这是代码,感谢大家的帮助!:)
import turtle
def main():
print("Project 1 by Amanda Basant")
main()
def draw_filled_square(turtle,size,color):
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(4):
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
def draw_picture():
window = turtle.Screen()
amanda = turtle.Turtle()
amanda.up()
amanda.goto(0,0)
amanda.down()
draw_filled_square(amanda,300,"blue")
draw_filled_square(amanda,300,"green")
draw_picture()我最终想要画这个enter image description here。我解决了我最初遇到的问题。我可以在盒子上写字母,但我现在正为如何装满盒子和与乌龟一起奔跑而苦苦挣扎。有人知道为什么盒子装不满吗?
发布于 2021-10-01 22:53:51
框没有填充的原因是turtle.end_fill()位于raw_filled_square()函数之后,而不是该函数的最后一行。你没有得到两个盒子的原因是你画的是一个在另一个的上面。让我们稍微修改一下这段代码,让它从你想要的图像中画出方框:
from turtle import Screen, Turtle
def main():
print("Project 1 by Amanda Basant")
screen = Screen()
draw_picture()
screen.exitonclick()
def draw_filled_square(turtle, size, color):
turtle.fillcolor(color)
turtle.begin_fill()
for _ in range(4):
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
def draw_picture():
amanda = Turtle()
for _ in range(2):
draw_filled_square(amanda, 300, "green")
amanda.right(90)
draw_filled_square(amanda, 300, "blue")
amanda.right(90)
main()

https://stackoverflow.com/questions/69395088
复制相似问题