python标准库--turtle库、random库概述、time库的概述

  • 1.turtle库
      • turtle库的引用有三种方式
      • turtle库与基本绘图
      • 练习绘图:
  • 2.random库概述
  • 3.time库的概述

1.turtle库

turtle库的引用有三种方式

python标准库--turtle库、random库概述、time库的概述_第1张图片
python标准库--turtle库、random库概述、time库的概述_第2张图片
python标准库--turtle库、random库概述、time库的概述_第3张图片

turtle库与基本绘图

①窗体函数 turtle.setup(width,height,startx,starty)
②画笔状态函数
pendown()放下画笔 pd() down()
penup()提起画笔 pu() up()
pensize()画笔宽度 width()
pencolor() 画笔颜色
color( 画笔 ,背景填充色 ) 画笔和背景填充色
begin_fill() 开始绘制
end_fill()结束绘制 ,与开始绘制一起使用

import turtle #导入 
turtle.color('red','blue')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()

python标准库--turtle库、random库概述、time库的概述_第4张图片python标准库--turtle库、random库概述、time库的概述_第5张图片
python标准库--turtle库、random库概述、time库的概述_第6张图片
python标准库--turtle库、random库概述、time库的概述_第7张图片

练习绘图:

import turtle as t
t.penup()#画笔抬起
t.goto(-200,-50)#移动位置
t.begin_fill()#开始绘制
t.color("red")#设置填充颜色
t.circle(40,steps=3)#三角形
t.end_fill()#结束绘制

t.penup()
t.goto(-100,-50)
t.begin_fill()
t.color('blue')
t.circle(40,steps=4)#四边形
t.end_fill()

t.penup()
t.goto(0,-50)
t.begin_fill()
t.color('green')
t.circle(40,steps=5)#五边形
t.end_fill()

t.penup()
t.goto(100,-50)
t.begin_fill()
t.color('yellow')
t.circle(40,steps=5)#六边形
t.end_fill()

t.penup()
t.goto(200,-50)
t.begin_fill()
t.color('purple')#圆
t.circle(40)
t.end_fill()

t.hideturtle()#隐藏画笔

python标准库--turtle库、random库概述、time库的概述_第8张图片

2.random库概述

python标准库--turtle库、random库概述、time库的概述_第9张图片

3.time库的概述

python标准库--turtle库、random库概述、time库的概述_第10张图片

你可能感兴趣的:(python,python)