标准库:turtle库
turtle库是海龟库体系在python语言功能的实现,非常适合作为程序设计入门教学内容。第一,它是python非常重要的图形绘制库。第二,turtle库是pythoon计算生态的代表,对于理解计算生态的概念和使用模式起到关键作用。第三,turtle库是编程入门库。
![ee2f1f89887efc7a1b08862a58d969dd.png](https://i-blog.csdnimg.cn/blog_migrate/4bc0f452cca449bf51f687d955e26dc0.jpeg)
功能函数
turtle库包含近百个功能函数。
- 绘制状态函数:pendown(),penup(),pensize(),以及对应的别名pd(),pu(),width();
- 颜色控制函数:color(),pencolor(),begin_fill(),end_fill();
- 运动控制函数:forward(),backward(),right(),left(),setheading(),goto(),circle(),以及对应的别名fd(),bk(),rt(),lt(),seth()。
引用turtle库函数需要使用import保留字,共三种方法:
第一种:import turtle
import turtle
turtle.circle(200)
第二种:from turtle import *
from turtle import *
turtle.circle(200)
第三种:import turtle as t
import turtle as t
turtle.circle(200)
这三种引用方式的作用是相同的。
![d5d921aa0235b03f63c7da985c02ec2c.png](https://i-blog.csdnimg.cn/blog_migrate/261b6fc4bf3b6724b6516e2e45c6a9ca.jpeg)
turtle库的22个考核函数的讲解如下:
- turtle.pendown() 别名 turtle.pd()
作用:落下画笔后,移动画笔绘制形状。
参数:无。
2.turtle.penup() 别名 turtle.pu()
作用:抬起画笔后,移动画笔不绘制形状。
参数:无。
3.turtle.pensize() 别名 turtle.width(width)
作用:设置画笔宽度,当无参数输入时返回当前画笔宽度。
参数:width:设置的画笔线条宽度,如果为None或者为空,则返回当前画笔宽度。
4.turtle.coclor()
可以表示为:turtle.color(colorstring)或者turtle.color((r,g,b))或者turtle.color(r,g,b)或者turtle.color(colorstr1,colorstr2)或者turtle.color((r1,g1,b1),(r2,g2,b2))
作用:返回设置画笔或背景颜色,当无参数输入时返回当前画笔及背景颜色。
参数:colorstring:表示颜色的字符串,例如:“Purple