• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

python控制台显示时钟的示例

PHP admin 11个月前 (05-31) 9次浏览 0个评论
复制代码 代码如下:

#!/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)


乐趣公园 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python控制台显示时钟的示例
喜欢 (0)
[sp91@qq.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址