方法一:
import turtle #用这种方式导入‘import 库名’在所有的方法面前必须添加库名turtle
for i in range(5):
turtle.pensize(10)
turtle.pencolor(1,0,1)
turtle.fd(200)
turtle.right(144)
方法二:
from turtle import * #用‘from 库名 import *’导入库,在下面所有的方法前面一定不能添加库名turtle
for i in range(5):
pensize(10)
pencolor(1,0,1)
fd(200)
right(144)
方法三:
import turtle as tl #用‘import 库名 as 别名’,在所有的方法面前必须添加别名tl
tl.penup() #将画笔设置为飞行模式
tl.fd(-150) #将画笔向左移动200像素
tl.pendown()#将画笔设置成工作模式/爬行模式
tl.pensize(10)
tl.pencolor(1,1,0)
tl.bgcolor('black')#设置背景颜色为黑色
tl.begin_fill()
tl.fillcolor('red')
for i in range(5):
tl.fd(100)
tl.left(72)
tl.fd(100)
tl.right(144)
tl.end_fill()
tl.hideturtle() #隐藏海龟画笔
tl.done() #关闭画笔功能