1.基本导出
import turtle
2.参数导出
import turtle as t
3.通配符导出
from turtle import*
4.以上三种导出的区别,即代码编写越来越简洁。
5.比如:
代码一:
import turtle#导出turtle模块
turtle.penup()#初学者可能好理解,也可写成turtle.pu()
turtle.pensize(4)
turtle.pendown()#turtle.pd()
代码二:
import turtle as t
t.penup()#也可写成t.pu()
t.pensize(4)
t.pendown()#也可写成t.pd()
代码三:
from turtle import*
penup()#简写pu()
pensize(4)
pendown()#简写pd()
6.代码实例:
#导出模块
from turtle import*
#定义设置
setup(750,500)#设置窗口大小,位于电脑屏幕中心位置
pu()#提笔,为penup的缩写
pensize(25)#笔头大小为25
pencolor("pink")#画笔颜色为粉红色
fd(-230)
seth(90)
pd()#落笔,为pendown的缩写
circle(-50,180)
circle(50,-180)
circle(75,-50)
circle(-190,-45)
pu()
fd(185)
seth(180)
fd(120)
seth(90)
pd()
circle(-75,-50)
circle(190,-45)
pu()
fd(184)
seth(0)
fd(80)
seth(90)
pd()
circle(-50,180)
circle(50,-180)
circle(75,-50)
circle(-190,-45)
pu()
fd(185)
seth(180)
fd(120)
seth(90)
pd()
circle(-75,-50)
circle(190,-45)
#横右箭头
pu()#提笔
fd(150)
seth(180)#角度180度,水平位置
fd(300)
pencolor("red")#画笔颜色为红色
pensize(10)#画笔速度
pd()#落笔,且画出线条
fd(-500)
seth(90)
fd(30)
fd(-60)
seth(30)
fd(60)
seth(150)
fd(60)
done() #结束1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
7.用python3运行之后的图
完成。欢迎讨论。