import turtle as ttime.sleep(10)
def watermelon(t, width, height, p_color="green", f_color="red"):
t.penup()
t.goto(0 - width / 2, 0 - height / 2)
t.pendown()
t.pensize(40)
t.pencolor(p_color)
t.fillcolor(f_color)
t.begin_fill()
for i in range(2):
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.forward(20)
t.end_fill()
def seed(t, x, y, r, c):
t.penup()
t.goto(x, y)
t.pendown()
t.color(c)
t.begin_fill()
for i in range(2):
t.circle(r, 90)
t.left(90)
t.end_fill()
def seeds(t, r=20, c="black"):
y = 120
for i in range(1, 5):
x = -240
for j in range(1, 7):
seed(t, x, y, r, c)
x = x + 90
y = y - 90
p1 = t.Turtle
#p1.hideturtle()
p2 = t.Turtle
#p2.hideturtle()
watermelon(p1, 600, 400, "lightgreen", "pink")
seeds(p2, c="yellow")
程序不止一个错,用变量设置不合理首先少了importtime#没有time模块,不能用time.sleep(10)的二是,既然用了importturtleast,怎么还要用p1=t.Turtle直接用p1=t就可以了同样p2=t.Turtle也要改为p2=t(其实p1,p2都可以不用的)最后不合理的是time.sleep(10)应该是放在程序最后,而不是在头上程序结果: