代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import pygame
import sys
import time
class Clock:
screen=pygame.display.set_mode((640, 480))
def __init__(self):
pygame.init()
pygame.display.set_caption('Binary Clock')
self.display()
def display(self):
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT:
exit(0)
elif e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
exit(0)
self.capture()
self.logic()
pygame.display.flip()
time.sleep(0.5)
def capture(self):
#Hour
#Row1
pygame.draw.circle(self.screen, (255, 255, 255), (70, 400), 30 ) # 颜色(白色) 位置 直径
#Row2
pygame.draw.circle(self.screen, (255, 255, 255), (170, 400), 30 ) # 第一行 1
pygame.draw.circle(self.screen, (255, 255, 255), (170, 300), 30 ) # 第二行 3
pygame.draw.circle(self.screen, (255, 255, 255), (170, 200), 30 ) # 第三行 9
#Min
#Row1
pygame.draw.circle(self.screen, (255, 255, 255), (270, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (270, 300), 30 )
#Row2
pygame.draw.circle(self.screen, (255, 255, 255), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (370, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (370, 200), 30 )
#Sec
#Row1
pygame.draw.circle(self.screen, (255, 255, 255), (470, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (470, 300), 30 )
#Row2
pygame.draw.circle(self.screen, (255, 255, 255), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (570, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (570, 200), 30 )
def logic(self):
#Hour
if int(time.asctime( time.localtime(time.time()) )[11])==1:# 表示小时的第一位 0,1,2三种
pygame.draw.circle(self.screen, (255, 0, 0), (70, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[11])==2:
pygame.draw.circle(self.screen, (0, 255, 0), (70, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==1:# 表示小时的第二位 0-9共10种
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==2:
pygame.draw.circle(self.screen, (0, 255, 0), (170, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==5:
pygame.draw.circle(self.screen, (0, 255, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==6:
pygame.draw.circle(self.screen, (0, 255, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==7:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (0, 255, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==8:
pygame.draw.circle(self.screen, (0, 255, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (0, 255, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==9:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
#Min
if int(time.asctime( time.localtime(time.time()) )[14])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==2:
pygame.draw.circle(self.screen, (0, 255, 0), (270, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==5:
pygame.draw.circle(self.screen, (0, 255, 0), (270, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==2:
pygame.draw.circle(self.screen, (0, 255, 0), (370, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==5:
pygame.draw.circle(self.screen, (0, 255, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==6:
pygame.draw.circle(self.screen, (0, 255, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==7:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (0, 255, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==8:
pygame.draw.circle(self.screen, (0, 255, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (0, 255, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==9:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
#Sec
if int(time.asctime( time.localtime(time.time()) )[17])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==2:
pygame.draw.circle(self.screen, (0, 255, 0), (470, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==5:
pygame.draw.circle(self.screen, (0, 255, 0), (470, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==2:
pygame.draw.circle(self.screen, (0, 255, 0), (570, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==5:
pygame.draw.circle(self.screen, (0, 255, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==6:
pygame.draw.circle(self.screen, (0, 255, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==7:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (0, 255, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==8:
pygame.draw.circle(self.screen, (0, 255, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (0, 255, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==9:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
if __name__ == "__main__":Clock()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。