问题分析:

绘制路径:

代码:

import turtle #引入绘图库turtle
def drawLine(draw): #绘制单段数码管
turtle.pendown() if draw else turtle.penup()
turtle.fd(40) #前进40像素
turtle.right(90)#旋转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.left(180)
turtle.penup() #为绘制后续数字确定位置
turtle.fd(20) #为绘制后续数字确定位置
def drawDate (date):#获得要输出的数字
for i in date:
drawDight(eval(i)) #通过eval()函数家将数字转化为整数 def main():
turtle.setup(800,350,200,200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
drawDate('')
turtle.hideturtle()
turtle.done()
main()

结果:

实现数码管效果

import turtle #引入绘图库turtle
def drawGap():#绘制数码管间隔,实现数码管效果
turtle.penup()
turtle.fd(5)
def drawLine(draw): #绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.fd(40) #前进40像素
drawGap()
turtle.right(90)#旋转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.left(180)
turtle.penup() #为绘制后续数字确定位置
turtle.fd(20) #为绘制后续数字确定位置
def drawDate (date):#获得要输出的数字
for i in date:
drawDight(eval(i)) #通过eval()函数家将数字转化为整数 def main():
turtle.setup(800,350,200,200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
drawDate('')
turtle.hideturtle()
turtle.done()
main()

import turtle,time #引入绘图库turtle time库
def drawGap():#绘制数码管间隔,实现数码管效果
turtle.penup()
turtle.fd(5)
def drawLine(draw): #绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.fd(40) #前进40像素
drawGap()
turtle.right(90)#旋转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.left(180)
turtle.penup() #为绘制后续数字确定位置
turtle.fd(20) #为绘制后续数字确定位置
def drawDate (date):#data为日期,格式为“%Y-%m=%d+”
turtle.pencolor("red")
for i in date:
if i=='-':
turtle.write('年',font=("Arial",18,"normal"))
turtle.pencolor("green")
turtle.fd(40)
elif i=='=':
turtle.write('月',font=("Arial",18,"normal"))
turtle.pencolor("blue")
turtle.fd(40)
elif i=='+':
turtle.write('日',font=("Arial",18,"normal"))
else:
drawDight(eval(i)) def main():
turtle.setup(800,350,200,200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
drawDate(time.strftime('%Y-%m=%d+',time.gmtime()))#获取系统时间并格式化
turtle.hideturtle()
turtle.done()
main()

【Python】七段数码管绘制问题的更多相关文章

  1. #Python语言程序设计Demo - 七段数码管绘制

    Python设计七段数码管绘制 单个数码管效果: 设计总数码管效果: Pyhton 编程: #七段数码管绘制 import turtle as t import time as T def drawG ...

  2. 使用Python的turtle库实现七段数码管绘制

    七段数码管绘制:七段数码管是由7段数码管拼接而成,每段有亮或不亮两种情况,改进的七段数码管还包括一个小数点位置.七段数码管能形成2=128种状态,其中部分状态能够显示易于人们理解的数字或字母含义.因此 ...

  3. 基于turtle库的七段数码管绘制

    ·文章结构 >样例及概览 >函数框架分析 >功能发展·样例及概览 七段数码管,是信号灯.电子表等很多设备的显示形式.而利用python的turtle库,我们也可以模拟着写出一个动态生 ...

  4. Python入门基础:七段数码管绘制

    1.在学习Python的过程中,运用所学的一些基础知识,进行一些简单的编程,可以收获很多乐趣.在生活中,LED灯无处不在,荧幕显示的广告词,给我们呈现出动态的视觉效果.下面,则以最简单的显示日期为例, ...

  5. python 利用turtle库绘制七段数码管的方式,绘制当前事件(时分秒00:00:00)

    # coding:utf-8# 绘制七段数码管,显示当前时间import timeimport turtle as tt # 绘制间隔def drawGap(): tt.penup() tt.fd(3 ...

  6. [Python 3.X]python练习笔记[2]-----用python实现七段数码管显示年月日

    #SevenDigitsDrawV2.py import turtle import time def drawGap(i):#绘制数码管间隔 turtle.penup() turtle.fd(i) ...

  7. python 七段管模块

    python 七段管模块 def drawGap(): #绘制数码管间隔 turtle.penup() turtle.fd(5) def drawLine(draw): #绘制单段数码管 drawGa ...

  8. SDL示例一:实现七段数码管的显示

    [时间:2017-05] [状态:Open] [关键词:sdl2,数字,七段数码管,图形显示,示例代码] 0 引言 本文是针对我的step-into-sdl2/7LedDigit的原理介绍,有兴趣的可 ...

  9. 【python】PIL 批量绘制图片矩形框工具

    工具采用PIL:Python Imaging Library,图像处理标准库.PIL功能非常强大,但API却非常简单易用. 安装PIL 在Debian/Ubuntu Linux下直接通过apt安装 $ ...

随机推荐

  1. NCE L6

  2. 目前最全的Python的就业方向

    Python是一门面向对象的编程语言,编译速度超快,从诞生到现在已经25个年头了.它具有丰富和强大的库,常被称为“胶水语言”,能够把用其他语言编写的各种模块(尤其是C/C++)很轻松地联结在一起.其特 ...

  3. jQuery 源码解析(三十一) 动画模块 便捷动画详解

    jquery在$.animate()这个接口上又封装了几个API,用于进行匹配元素的便捷动画,如下: $(selector).show(speed,easing,callback)        ;如 ...

  4. ES6 - 基础学习(2): 新的变量声明方式 let 与 const

    ES6)新增加了两个重要的 JavaScript 关键字:let 和 const.以前声明变量时只有一种方式:var,ES6对声明方式进行了扩展,现在可以有三种声明方式了. 1.var:variabl ...

  5. App工程结构

    在经过千辛万苦各种填坑终于安装好了Android Studio之后,在其自带的模拟器上成功运行了第一个APP(hello world),通过这个APP首先研究了一下APP基本的工程结构,从而使后面的开 ...

  6. 源码浅析:InnoDB聚集索引如何定位到数据的物理位置,并从磁盘读取

    索引结构概述: MyISAM索引文件和数据文件是分离的,索引文件仅保存数据记录的地址.这与Oracle的索引结构相似,比较好理解.那么,常用的Innodb聚集索引结构是怎样的呢? InnoDB的数据文 ...

  7. 静态存储SRAM设计

    SRAM即静态随机存取存储器.它是具有静止存取功能的内存,不需要刷新电路便能保存它内部存储的数据.在工业与科学用的很多子系统,汽车电子等等都用到了SRAM.现代设备中很多都嵌入了几千字节的SRAM.实 ...

  8. 2、CentOS7密码重置

    一.重启系统,在开机过程中,快速按下键盘上的方向键↑和↓.目的是告知引导程序,我们需要在引导页面选择不同的操作,以便让引导程序暂停.  以下是暂停后的界面,可以查看下方的英文可知↑和↓的作用.  二. ...

  9. Webdriver启动Firefox浏览器后,页面显示空白

    在使用pycharm码代码时编译总是出错,后来验证发现浏览器启动后出现问题.白白耗了我2个小时.我把我的解决方案写出来,希望对大家有帮助. 1.现象:起初安装的时候总是能正常运行,有一天突然发现Web ...

  10. docker之阿里云centos 7.x 启动容器报错处理办法

    最近阿里云服务器(操作系统centOS 7.x) 安装docker,参照阿里云帮助文档https://help.aliyun.com/document_detail/51853.html?spm=a2 ...