AttributeError: 'Turtle' object has no attribute 'done'

問題:
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()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章