hw中倒计时脚本编写

hw快结束时候要求给领导展示个倒计时,就手写了个,虽然最后也么有用上哈哈哈

# https://www.jianshu.com/p/0b5dfd0f6fd7
from tkinter import *
from datetime import datetime


class TestTime(object):
    def __init__(self, master=None):
        self.root = master
        self.root.geometry('800x300')
        self.root.resizable(width=True, height=True)
        self.updatetime()

    def updatetime(self):
        self.labelA = Label(self.root, font='楷体 -60 bold', foreground='red')
        self.labelA.pack()
        self.labelF = Label(self.root, text="")
        self.labelF.pack()

        self.updateA()

    def updateA(self):
        # self.now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        future = datetime(2022, 8, 8, 18, 0, 0)
        now = datetime.now()
        diff = future - now
        day = diff.days
        hour = diff.seconds // 3600
        minute = (diff.seconds % 3600) // 60
        second = (diff.seconds % 3600) % 60
        text = "HY结束倒计时:\r\r{}天{}小时{}分{}秒".format(day, hour, minute, second).strip()
        self.labelA.configure(text=text, bg='#BFEFFF',) #bg='#BFEFFF',
        self.root.after(1000, self.updateA)


if __name__ == '__main__':
    root = Tk()
    root.title('HY倒计时')
    root.configure(bg='#BFEFFF',)
    # 窗口置顶.
    root.wm_attributes('-topmost', 1)
    TestTime(root)
    root.mainloop()
Footer

posted @ 2022-08-09 23:30  总得前行  阅读(71)  评论(0编辑  收藏  举报