python(10)---七段数码管(2)

  今天根据网上的教程修改了七段数码管的程序,引入了time库函数,这样程序可以

根据系统的时间画出七段数码管了。废话不多说了,直接上程序:

 1 #!/usr/bin/env python3
 2 # -*- coding: utf-8 -*-
 3 #Segement7_2.py
 4 import turtle,time
 5 def drawGap():
 6     turtle.penup()
 7     turtle.fd(5)
 8 def drawline(draw):
 9     drawGap()
10     turtle.pendown() if draw else turtle.penup()
11     turtle.fd(40)
12     drawGap()
13     turtle.right(90)
14 def drawdigit(digit):
15     drawline(True) if digit in [2,3,4,5,6,8,9] else drawline(False)
16     drawline(True) if digit in [0,1,3,4,5,6,7,8,9] else drawline(False)
17     drawline(True) if digit in [0,2,3,5,6,8,9] else drawline(False)
18     drawline(True) if digit in [0,2,6,8] else drawline(False)
19     turtle.left(90)
20     drawline(True) if digit in [0,4,5,6,8,9] else drawline(False)
21     drawline(True) if digit in [0,2,3,5,6,7,8,9] else drawline(False)
22     drawline(True) if digit in [0,1,2,3,4,7,8,9] else drawline(False)
23     turtle.left(180)
24     turtle.penup()
25     turtle.fd(20)
26 def drawdate(date):
27     turtle.pencolor("red")
28     for i in date:
29         if i==‘-‘:
30             turtle.write("年",font=("Arial",18,"normal"))
31             turtle.pencolor("green")
32             turtle.fd(40)
33         elif i==‘=‘:
34             turtle.write("月",font=("Arial",18,"normal"))
35             turtle.pencolor("blue")
36             turtle.fd(40)
37         elif i==‘+‘:
38             turtle.write("日",font=("Arial",18,"normal"))
39         else:
40             drawdigit(eval(i))
41 def main():
42     turtle.setup(800,350,200,200)
43     turtle.penup()
44     turtle.fd(-300)
45     turtle.pensize(5)
46     drawdate(time.strftime("%Y-%m=%d+",time.gmtime()))
47     #drawdate(‘20181010‘)
48     turtle.hideturtle()
49     turtle.done()
50 main()

segment7_2

  

原文地址:https://www.cnblogs.com/xuelanga000/p/12651190.html

时间: 2024-08-09 00:12:42

python(10)---七段数码管(2)的相关文章

【Python】七段数码显示管

#DrawSevenSegDisplay.py import turtle, datetime def drawLine(draw): #绘制单段数码管 turtle.pendown() if draw else turtle.penup() turtle.fd(40) turtle.right(90) def drawDigit(digit): #根据数字绘制七段数码管 drawLine(True) if digit in [2,3,4,5,6,8,9] else drawLine(False

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

1.在学习Python的过程中,运用所学的一些基础知识,进行一些简单的编程,可以收获很多乐趣.在生活中,LED灯无处不在,荧幕显示的广告词,给我们呈现出动态的视觉效果.下面,则以最简单的显示日期为例,绘制七段数码管. 2.何为七段数码管 数码管是一种价格便宜.使用简单的电子器件,广泛应用于价格较低的电子类产品中,其中,七段数码管最为常用.七段数码管(Seven-segment Indicator)由七段数码管拼接而成,每段有亮或不亮的两种情况,且包括一个小数点的位置. 3.在绘制数码管的显示动态

七段数码管

#七段数码管 import turtle, time def drawGap(): #绘制数码管间隔 turtle.penup() turtle.fd(5) def drawLine(draw): #绘制单段数码管 drawGap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) drawGap() turtle.right(90) def drawDigit(d): #根据数字绘制七段数码管 drawLine(True)

Python<10>文件基础

常见的文件操作 output = open('data','w')       #创建文件 w为写入 input = open('data','r')        #r为读写 若不写属性  默认为r aString = input.read()          #读整个文件到一个字符串 aString = input.readlines()      #读整个文件到字符串列表 aString = input.read(N)         #读N个字节 aString =input.read

python(10)——局部变量、全局变量

局部变量:在局部生效的,出了这个变量的作用域,这个变量就失效了.函数内部定义的变量就是局部变量,函数运行完就释放该变量内存 全局变量:在整个程序里面都生效的,在程序最前面定义的都是全局变量,全局变量如果要在函数中修改的话,需要加global关键字声明,如果是list.字典和集合的话,则不需要加global关键字,直接就可以修改 . 尽量少用全局变量,原因:1.若全局变量被修改,影响较大:2.全局变量在python文件运行完才会释放,占内存 name ='wangchan' #全局变量 每个函数里

词云制作没那么难,Python 10 行代码就实现了!

写在前面 想必大家有一个问题.什么是词云呢? 词云又叫名字云,是对文本数据中出现频率较高的"关键词"在视觉上的突出呈现,形成关键词的渲染形成类似云一样的彩色图片,从而一眼就可以领略文本数据的主要表达意思.. 网页上有许多词云的效果图: 而且,目前有许多制作词云的工具: 但是作为一个学习Python的程序员来说,我更喜欢通过自己的编程去解决问题. 而且用Python制作词云只需十行代码就行了哦~ 一起来看看吧! 代码块 import matplotlib.pyplot as plt fr

Python:10分钟搞定不写代码的爬虫

代码自己敲 使用 Chrome 浏览器插件 Web Scraper 可以轻松实现网页数据的爬取,不写代码,鼠标操作,点哪爬哪,还不用考虑爬虫中的登陆.验证码.异步加载等复杂问题. Web Scraper插件 Web Scraper 官网中的简介: Web Scraper Extension (Free!)Using our extension you can create a plan (sitemap) how a web site should be traversed and what s

初识Python(10)__Python模块

模块 什么是模块 自我包含并且有组织的代码片断就是模块( module ) 模块是Pyhon最高级别的程序组织单元,它将程序代码和数据封装起来以便重用.实际的角度,模块往往对应Python程序文件.每个文件都是一个模块,并且模块导入其他模块之后就可以使用导入模块定义的变量名.模块可以由两个语句和一个重要的内置函数进行处理.import: 使客户端(导入者)以一个整体获取一个模块.from:容许客户端从一个模块文件中获取特定的变量名.reload:在不中止Python程序的情况下,提供了一个重新载

python-函数和代码复用—七段数码管绘制和爱心

import turtledef curvemove(): for i in range(200): turtle.right(1) turtle.forward(1)def drawGap(): turtle.penup() turtle.fd(5)def drawLine(draw): drawGap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) drawGap() turtle.right(90)def drawD