画图这个东西说实话就是前期提高兴趣的,所以该教程不会太长。本篇会介绍turtle库的一些简单用法。
话不多少直接上代码,重复的关键词注释只写一遍。
import turtle as t
t.speed(0) #速度
t.hideturtle() #隐藏画笔
#外面的大正方形
t.up() #抬笔
t.pensize(10) #画笔粗细
t.goto(-150,100) #移动
t.down() #落笔
t.forward(300) #画直线
t.right(90) #右转
t.forward(200)
t.right(90)
t.forward(300)
t.right(90)
t.forward(200)
#内部的小正方形
t.up()
t.goto(-120,70)
t.down()
t.right(90)
t.forward(240)
t.right(90)
t.forward(140)
t.right(90)
t.forward(240)
t.right(90)
t.forward(140)
#内部表情
#左
t.up()
t.goto(-75,20)
t.right(70)
t.down()
t.forward(40)
#右
t.up()
t.goto(45,30)
t.right(40)
t.down()
t.forward(40)
#中部
#左
t.up()
t.goto(-30,-20)
t.right(70)
t.down()
t.circle(20,180)
#右
t.up()
t.goto(10,-20)
t.left(180)
t.down()
t.circle(20,180) #画圆 注:括号内第一个数是圆的半径,第二个数是切的角度
#上部天线
#左
t.up()
t.goto(-5,100)
t.right(-60)
t.down()
t.forward(85)
#右
t.up()
t.goto(5,100)
t.right(90)
t.down()
t.forward(85)
#下部支架
#左
t.up()
t.goto(-120,-105)
t.left(210) #左转
t.down()
t.circle(13,180)
#右
t.up()
t.goto(90,-105)
t.left(180)
t.down()
t.circle(13,180)
#字
t.up()
t.goto(230,-280)
t.down()
t.write("by--宋勃逸", font=('Arial', 15, 'bold italic'))
t.done() #结束 注:1.就算后面还有代码也不会执行 2.使画布不消失
接下来的代码可以再画布上面打印出时间。
可以将本段代码加载上一段代码的t.done()前
可以使画布显示时间
import turtle as t
from time import sleep
t.clearscreen()
t.speed(0) #速度
t.hideturtle() #隐藏画笔
from datetime import datetime
now=datetime.now()
t.up()
t.goto(200,-300)
t.down()
print(now)
t.write(now)
t.done()
注:1.注意标点是否为英文
2.注意单词拼写是否正确
3.很多语句后面都需要加英文状态的括号,括号里很有可能是空着的但一定要留着括号
如有错误请联系作者邮箱:official@ling2023.xyz