zoukankan      html  css  js  c++  java
  • python pygame--倒计时

    import pygame,sys,time,datetime
    
    class decTime(object):
       #将秒转化为时分秒 def __init__(self,totalTime): self.sec = totalTime self.hour = int(self.sec / 3600) self.sec = self.sec % 3600 self.minute = int(self.sec / 60) self.sec = int(self.sec % 60) #时间减 def subTime(self): if self.sec > 0: self.sec -= 1 else: if self.minute > 0: self.minute -= 1 self.sec = 59 else: if self.hour > 0: self.hour -= 1 self.minute = 59 self.sec = 59 else: return 0 if __name__=='__main__': pygame.init()   #窗口宽,高 size = width,height = 600,100 screen = pygame.display.set_mode(size)   #title pygame.display.set_caption("倒计时……")   #背景色 bg = (255,255,255)   #字体 my_font = pygame.font.Font(None,40)   #行高 line_height = my_font.get_linesize() position = 0 screen.fill(bg)   strtime = '2017-7-19 00:00:00' now = datetime.datetime.now() deadline = datetime.datetime.strptime(strtime,'%Y-%m-%d %H:%M:%S') subtime = (deadline - now).seconds temp = decTime(subtime) while (temp.hour>0) or (temp.minute>0) or (temp.sec>0): screen.fill(bg) ch = str(temp.hour)+':'+str(temp.minute)+':'+str(temp.sec) screen.blit(my_font.render(ch,True,(0,255,0)),(0,position)) temp.subTime() time.sleep(1)      #休眠1秒刷新屏幕 pygame.display.flip()
    效果图:
  • 相关阅读:
    Java实现 LeetCode 461 汉明距离
    在Linux运行期间升级Linux系统(Uboot+kernel+Rootfs)
    AM335x(TQ335x)学习笔记——挂载Ramdisk
    Ramdisk文件系统的制作与调试运行
    u-boot向linux内核传递启动参数(详细)
    uboot环境变量与内核MTD分区关系
    MMU
    INTERRUPT CONTROLLER
    UART
    GPIO
  • 原文地址:https://www.cnblogs.com/slothrbk/p/7202630.html
Copyright © 2011-2022 走看看