python控制台显示时钟的示例

#!/usr/bin/env python
# coding: utf-8
#
#
# show time in console
#
import sys
import time

raws = ”’
.–.

| |

`–`
.
/|

|

—.

—`

`—
—.

—|

—`
. .

`–|

|
.—

`–.

—`
.—

|–.

`–`
.–.

` |

|
.–.

|–|

`–`
.–.

`–|

—`
”’.strip()
numbers = {}
def init():
for num in range(10):
numbers[str(num)] = []
lineno = 0
for line in raws.split(‘n’):
line = line.ljust(4)
arr = []
for char in line:
arr.append(char) # != ‘ ‘)
numbers[str(lineno/5)].append(arr)
lineno += 1
numbers[‘:’] = [[‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘-‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘-‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘]]
numbers[‘ ‘] = [[‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘], [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘]]
def print_num(digtal):
digtal = str(digtal)
screen = []
for i in range(5):
screen.append([])
for num in digtal:
for i, linechar in enumerate(numbers[num]):
for char in linechar:
screen[i].append(char)
screen[i].append(‘ ‘)
for line in screen:
print ”.join(line)
init()
def cls():
sys.stdout.write(‘33[2J33[0;0H’)
sys.stdout.flush()

while True:
t = time.strftime(“%H:%M:%S”)
cls(); print_num(t)
time.sleep(1)
t = time.strftime(“%H %M %S”)
cls(); print_num(t)
time.sleep(1)

郑重声明:本网站发布的内容(图片、视频和文字)以及用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服

发表评论

登录后才能评论