下班倒计时

等着下班回家,太煎熬了,写个倒计时,注释是不可能有注释的,只想下班

from PyQt5 import QtWidgets,QtCore,QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
import sys
import time


class RefreshWidget(QWidget):
    def __init__(self,parent=None):
        super(RefreshWidget, self).__init__(parent)

        layout=QVBoxLayout()
        self.setWindowTitle("回家倒计时")
        self.label = QLabel()
        self.label.setAlignment(Qt.AlignCenter)
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(18)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)

        pushButton = QPushButton("开始")
        pushButton.clicked.connect(self.call_back_btn_func)

        layout.addWidget(self.label)
        layout.addWidget(pushButton)

        self.setLayout(layout)
        self.resize(400, 300)
        # 回家时间
        self.end_time = '2022-01-28 19:00:00'

    def call_back_btn_func(self):

        while True:
            h, m, s = self.get_time()
            self.label.setText(f'回家倒计时:{h}:{m}:{s}')
            # 实时刷新
            app.processEvents()
            time.sleep(1)
            if h==0 and m==0 and s==0:break

    def get_time(self):
        time_arr = time.strptime(self.end_time, "%Y-%m-%d %H:%M:%S")
        ts = int(time.mktime(time_arr))

        a = int(ts - time.time())
        h = int(a / 3600)
        m = int((a - h * 3600) / 60)
        s = a - h * 3600 - m * 60
        # print(f'toatls:{a},h:{h},m:{m},s:{s}')
        return h, m, s

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window=RefreshWidget()
    window.show()
    sys.exit(app.exec())


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值