源码:

import turtle    #导入turtle库,turtle库是python的基础绘图库turtle.pensize(30)    #设置画笔粗细
for i in range(30):turtle.circle(i*10,60)    #循环画圆30次,每次画60度并且半径增加10,也就是说画了30×60度的圆形,1800度,即5圈
turtle.done()    #画完之后,使面板停留,否则画笔画完将自动关闭

效果图:

源码:

# -*- coding:utf-8 –*-
# 用turtlr画时钟
# 以自定义shape的方式实现
import turtle as t
import datetime as d
def skip(step):  # 抬笔,跳到一个地方t.penup()t.forward(step)t.pendown()
def drawClock(radius):  # 画表盘t.speed(0)t.mode("logo")  # 以Logo坐标、角度方式t.hideturtle()t.pensize(7)t.home()  # 回到圆点for j in range(60):skip(radius)if (j % 5 == 0):t.forward(20)skip(-radius - 20)else:t.dot(5)skip(-radius)t.right(6)
def makePoint(pointName, len):  # 钟的指针,时针、分针、秒针t.penup()t.home()t.begin_poly()t.back(0.1 * len)t.forward(len * 1.1)t.end_poly()poly = t.get_poly()t.register_shape(pointName, poly)  # 注册为一个shape
def drawPoint():  # 画指针global hourPoint, minPoint, secPoint, fontWritermakePoint("hourPoint", 100)makePoint("minPoint", 120)makePoint("secPoint", 140)hourPoint = t.Pen()  # 每个指针是一只新turtlehourPoint.shape("hourPoint")hourPoint.shapesize(1, 1, 6)minPoint = t.Pen()minPoint.shape("minPoint")minPoint.shapesize(1, 1, 4)secPoint = t.Pen()secPoint.shape("secPoint")secPoint.pencolor('red')fontWriter = t.Pen()fontWriter.pencolor('gray')fontWriter.hideturtle()
def getWeekName(weekday):weekName = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']return weekName[weekday]
def getDate(year, month, day):return "%s-%s-%s" % (year, month, day)
def realTime():curr = d.datetime.now()curr_year = curr.yearcurr_month = curr.monthcurr_day = curr.daycurr_hour = curr.hourcurr_minute = curr.minutecurr_second = curr.secondcurr_weekday = curr.weekday()t.tracer(False)secPoint.setheading(360 / 60 * curr_second)minPoint.setheading(360 / 60 * curr_minute)hourPoint.setheading(360 / 12 * curr_hour + 30 / 60 * curr_minute)fontWriter.clear()fontWriter.home()fontWriter.penup()fontWriter.forward(80)# 用turtle写文字fontWriter.write(getWeekName(curr_weekday), align="center", font=("Courier", 14, "bold"))fontWriter.forward(-160)fontWriter.write(getDate(curr_year, curr_month, curr_day), align="center", font=("Courier", 14, "bold"))t.tracer(True)print(curr_second)t.ontimer(realTime, 100)  # 每隔100毫秒调用一次realTime()
def main():t.tracer(False)drawClock(160)drawPoint()realTime()t.tracer(True)t.mainloop()
if __name__ == '__main__':main()

效果图:

源码:

import turtle as t
import datetime
def drawGap(): #绘制数码管间隔t.penup()t.fd(5)
def drawLine(draw):   #绘制单段数码管drawGap()t.pendown() if draw else t.penup()t.fd(40)drawGap()t.right(90)
def drawDigit(d): #根据数字绘制七段数码管drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False)drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,2,6,8] else drawLine(False)t.left(90)drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False)drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False)t.left(180)t.penup()t.fd(20)
def drawDate(date):t.pencolor("red")for i in date:if i == '-':t.write('年', font=("Arial", 18, "normal"))t.pencolor("green")t.fd(40)elif i == '=':t.write('月', font=("Arial", 18, "normal"))t.pencolor("blue")t.fd(40)elif i == '+':t.write('日', font=("Arial", 18, "normal"))else:drawDigit(eval(i))
def main():t.setup(800, 350, 200, 200)t.penup()t.fd(-350)t.pensize(5)drawDate(datetime.datetime.now().strftime('%Y-%m=%d+'))t.hideturtle()t.exitonclick()
main()

效果图:

Python-turtle库绘制蚊香、走动的时钟和数码管日期相关推荐

  1. Python Turtle库绘制小黄脸表情包

    Python Turtle库绘制小黄脸表情包 下面只有一个表情的代码 #!/usr/bin/env python # -*- coding:utf-8 -*- __author__: "TC ...

  2. Python turtle库绘制复杂漫威蜘蛛侠Spiderman

    演示效果 点击播放:Python123平台 济南大学_盛亚琪_spiderman (https://www.python123.io/index/turtles/5c95d01e24577506dc7 ...

  3. python random库画多彩蟒蛇,Python Turtle库绘制蟒蛇

    使用Python Turtle库来绘制蟒蛇 import turtle引入了海龟绘图体系 使用setup函数,设定了一个宽650像素和高350像素的窗体,其位置左上角坐标是200,200 说明位置在距 ...

  4. 使用python turtle库绘制一个三角形_使用turtle库绘制一个叠加等边三角形,图形效果如下:...

    原博文 2020-09-14 23:11 − import turtle turtle.setup(650,350,200,200) turtle.penup() turtle.pensize(1) ...

  5. 用Python turtle库绘制蟒蛇

    Python的函数库 Python语言与C语言Java类似,可以大量使用外部函数库包含在安装包中的函数库:. 比如math, random, turtle等其他函数库,其他函数库用户根据代码需求自行安 ...

  6. 用Python turtle库 绘制皮卡丘

    Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行 ...

  7. Python turtle库绘制同心圆

    今天了解了Python中用于绘制图像的turtle库 然后发现这真的是一个很好玩的库 放上大神的有关绘图的文章 https://blog.csdn.net/zengxiantao1994/articl ...

  8. 用python函数画德国国旗代码_每日一程-11.利用Python turtle库绘制国旗

    Author: Notus(hehe_xiao@qq.com) Create: 2019-02-19 Update: 2019-02-19 利用turtle模块绘制五星红旗 原理不算太复杂,只是需要稍 ...

  9. 使用python turtle库绘制一个三角形和一个五角星_使用turtle库绘制一个五角星 如何采用Python语言绘制一个五角星...

    如何采用Python语言绘制一个五角星 #./usr/bin/env python import turtle import time turtle.forward(100) turtle.right ...

最新文章

  1. MySQL图形处理软件Navicat字体配置(乱码解决)
  2. Careless Me
  3. TypeScript 2.7 版本发布
  4. 跨服务器 快速 导入数据表记录 Insert into SELECT
  5. oracle spacial,Oracle Spacial(空间数据库)geometry元数据结构
  6. EEPlat 主子表和对象引用配置实例
  7. android用java写文本框_Android 自动完成文本框的实例
  8. mqtt server python_使用python实现mqtt的发布和订阅
  9. OpenCV学习(13) 细化算法(1)(转)
  10. context:annotation-config、context:component-scan
  11. K8S 使用 SideCar 模式部署 Filebeat 收集容器日志
  12. 51单片机入门——安装keil5及烧录下载器
  13. Linux常用命令大全 阶段性总结(一)
  14. 丹佛大学计算机专业,丹佛大学计算机工程专业排名第(2018年USNEWS美国排名)...
  15. 火狐浏览器Firebug控制台显示本页面不包含 javascript的解决方案 debugger 无效解决方案
  16. P3435 [POI2006]OKR-Periods of Words [Kmp, next数组]
  17. XCTF-高手进阶区:mfw
  18. The DiskSpace quota of /five is exceeded: quota = 4096 B = 4 KB but diskspace consumed = 402653184
  19. [深入研究4G/5G/6G专题-45]: 5G Link Adaption链路自适应-1-总体架构
  20. 夏日炎炎玩转新加坡:盘点室内景点和夜游好去处

热门文章

  1. 2018最新Web前端经典面试试题及答案
  2. Hyper-V Server 存储分层
  3. mysql查询与索引优化2
  4. QT Creator 环境使用 remote debug 调试 arm 程序
  5. 天声人語2008年05月04日-蔬菜的阴谋
  6. 复旦的NLP——fudanNLP
  7. 重新认识鸿鹄与燕雀的区别
  8. 前端开发工程化探讨--基础篇
  9. JavaScript数组合并
  10. 高效开发Android App的10个建议