主页 > 知识库 > Python绘制数码晶体管日期

Python绘制数码晶体管日期

热门标签:百度AI接口 呼叫中心市场需求 客户服务 企业做大做强 硅谷的囚徒呼叫中心 Win7旗舰版 电话运营中心 语音系统

本文实例为大家分享了Python绘制数码晶体管日期的具体代码,供大家参考,具体内容如下

源码:

drawLine(draw) 画一条线
drawDight(dight) 画一个数字
drawDate(date) 画一组数字

代码:

import turtle, time


def drawLine(draw):
 turtle.pendown() if draw else turtle.penup()
 turtle.fd(40)
 turtle.right(90)


def drawDight(dight):
 drawLine(True) if dight in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
 drawLine(True) if dight in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
 drawLine(True) if dight in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
 drawLine(True) if dight in [0, 2, 6, 8] else drawLine(False)
 turtle.left(90)
 drawLine(True) if dight in [0, 4, 5, 6, 8, 9] else drawLine(False)
 drawLine(True) if dight in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
 drawLine(True) if dight in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
 turtle.right(180)
 turtle.penup()
 turtle.fd(20)


def drawDate(date):
 turtle.pencolor("red")
 for i in date:
  if i == '-':
   turtle.write('年', font=("微软雅黑", 32, "normal"))
   turtle.pencolor("green")
   turtle.fd(80)
  elif i == '=':
   turtle.write('月', font=("微软雅黑", 32, "normal"))
   turtle.pencolor("blue")
   turtle.fd(80)
  elif i == '+':
   turtle.write('日', font=("微软雅黑", 32, "normal"))
   turtle.pencolor("red")
   turtle.fd(80)
  elif i == '/':
   turtle.write('时', font=("微软雅黑", 32, "normal"))
   turtle.pencolor("green")
   turtle.fd(80)
  elif i == '*':
   turtle.write('分', font=("微软雅黑", 32, "normal"))
   turtle.pencolor("blue")
   turtle.fd(80)
  elif i == '.':
   turtle.write('秒', font=("微软雅黑", 32, "normal"))
   turtle.fd(80)
  else:
   drawDight(eval(i))


if __name__ == '__main__':
 # turtle.setup() 我用的是pycharm,所以没有设置画布,idle下需要设置
 turtle.penup()
 turtle.fd(-350)
 turtle.pensize(5)
 turtle.speed(1000) # 速度再大也没感觉了
 drawDate(time.strftime('%Y-%m=%d+', time.localtime()))
 # 这里千万不要用time.gmtime()),获取的是UTC时区(0时区)的struct_time
 # 踩了半天坑

 turtle.right(90)
 turtle.fd(120)
 turtle.right(90)
 turtle.fd(660)
 turtle.right(180)
 drawDate(time.strftime('%H/%M*%S.', time.localtime()))
 turtle.hideturtle()
 turtle.done()

效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
  • Python3时间转换之时间戳转换为指定格式的日期方法详解
  • python获取指定时间段内特定规律的日期列表
  • python (logging) 日志按日期、大小回滚的操作
  • Python时间和日期库的实现
  • Python tkinter实现日期选择器
  • Pycharm创建python文件自动添加日期作者等信息(步骤详解)
  • python实现按日期归档文件
  • 基于python获取本地时间并转换时间戳和日期格式
  • python 带时区的日期格式化操作
  • 如何使用 Python 读取文件和照片的创建日期
  • Python 常用日期处理 -- calendar 与 dateutil 模块的使用
  • python 常用日期处理-- datetime 模块的使用
  • python自动提取文本中的时间(包含中文日期)
  • Python 处理日期时间的Arrow库使用
  • Python 日期与时间转换的方法
  • Python如何将字符串转换为日期
  • python实现将中文日期转换为数字日期
  • 教你怎么用python实现字符串转日期

标签:海南 济南 安康 山西 山西 喀什 长沙 崇左

巨人网络通讯声明:本文标题《Python绘制数码晶体管日期》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266