問題:
AttributeError: ‘Turtle’ object has no attribute ‘done’
代碼:
from turtle import Turtle
t = Turtle()#這邊一定要實例化
t.penup()
t.fd(-250)
t.pendown()
t.pensize(25)
t.pencolor("purple")
t.seth(-40)
for i in range(4):
t.circle(40, 80)
t.circle(-40, 80)
t.circle(40, 80 / 2)
t.fd(40)
t.circle(16, 180)
t.fd(40 * 2 / 3)
t.done()#這裏報錯,留不住頁面
原因
done是模塊turtle的功能,而不是turtle.Turtle類的方法
正確使用:
import turtle
from turtle import Turtle
t = Turtle()
t.penup()
t.fd(-250)
t.pendown()
t.pensize(25)
t.pencolor("purple")
t.seth(-40)
for i in range(4):
t.circle(40, 80)
t.circle(-40, 80)
t.circle(40, 80 / 2)
t.fd(40)
t.circle(16, 180)
t.fd(40 * 2 / 3)
turtle.done()