1.Python标准库中的GUI界面
turtle的简单使用
# 导入turtle as 是给起一个别名
import turtle as t
# 让gui界面一直显示, 所有执行的代码要写在此函数之前
t.done()
2. 画笔运动命令
t.forward(distance)——向当前画笔方向移动distance像素长。简写为t.fd(distance)。
t.backward(distance)——向当前画笔相反方向移动distance像素长度
t.right(degree)——顺时针移动degree°。简写为t.rt(distance)。
t.left(degree)——逆时针移动degree°。简写为t.lt(degree)。
t.pendown()——移动时绘制图形,缺省时也为绘制。画笔落下,留下痕迹。简写为t.pd()。
t.penup()——移动时不绘制图形,提起笔,用于另起一个地方绘制时用。画笔抬起,不留痕迹。
t.goto(x,y)——将画笔移动到坐标为x,y的位置
t.speed(speed)——画笔绘制的速度范围[0,10]整数
t.circle()——画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆
3. 画笔控制命令
t.pensize(width)——绘制图形时的宽度
t.pencolor()——画笔颜色
t.fillcolor(colorstring)——绘制图形的填充颜色
t.color(color1, color2)——同时设置pencolor=color1, fillcolor=color2
t.filling()——返回当前是否在填充状态
t.begin_fill()——准备开始填充图形
t.end_fill()——填充完成
t.hideturtle()——隐藏箭头显示
4.字符串
定义形式 '' " ' '
# 切片 对序列截取一部分的操作,适用于列表
name = 'abcdefg'
# [起始位置:终止位置:步长] 左闭右开
print(name[1:4])
# a c e g
print(name[0:7:2])
# 全切片的时候可以省略初始和终止位置
print(name[::2])
5.turtle简易GUI绘图
import turtle as t
t.pensize(10)
#设置画笔颜色为蓝色
t.color('pink')
t.penup()
t.goto(-260, 0)
t.pd()
# 绘制 N
t.left(90)
t.forward(80)
t.right(145)
# 简写
t.fd(100)
t.lt(145)
t.fd(80)
# 绘制E
t.penup()
t.goto(-130, 0)
t.pd()
t.left(90)
t.forward(40)
t.right(90)
t.forward(80)
t.penup()
t.goto(-130,40)
t.pd()
t.left(90)
t.forward(40)
t.penup()
t.goto(-130,80)
t.pd()
t.forward(40)
t.penup()
t.goto(-100, 80)
t.pd()
t.left(90)
t.forward(60)
t.penup()
t.goto(-50, 80)
t.pd()
t.forward(60)
t.penup()
t.goto(-100, 20)
t.pd()
t.circle(25,180)
t.penup()
t.goto(20, 60)
t.pd()
t.circle(22,270)
t.circle(-22,270)
t.penup()
t.goto(100, 60)
t.pd()
t.circle(22, 180)
t.fd(40)
t.penup()
t.goto(100, 20)
t.pd()
t.circle(-22, 180)
t.penup()
t.goto(100, 20)
t.pd()
t.fd(40)
t.penup()
t.goto(140, 0)
t.pd()
t.forward(80)
t.penup()
t.goto(180,40)
t.pd()
t.left(90)
t.forward(40)
t.penup()
t.goto(180,80)
t.pd()
t.forward(40)
t.penup()
t.goto(230, 0)
t.pd()
t.right(90)
t.forward(80)
t.penup()
t.goto(255,80)
t.pd()
t.lt(90)
t.forward(50)
t.done()