吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 825|回复: 7
收起左侧

[Python 原创] 时钟小例子

[复制链接]
999CWCR999 发表于 2024-8-2 14:00
image.png


源码:
[Python] 纯文本查看 复制代码
import sys

from PyQt5.QtCore import QTimer, QDateTime, QSize, Qt
from PyQt5.QtWidgets import QVBoxLayout, QApplication
from qfluentwidgets import CardWidget, TransparentToolButton, ProgressRing, BodyLabel, CaptionLabel


class dateTime_panel(CardWidget):
        """
        时间组件
        """

        def __init__(self, p=None):
                super(dateTime_panel, self).__init__(p)
                self.ui_init()
                self.timer_init()
                self.timer.start()

        def timer_init(self):
                self.timer = QTimer(self)
                self.timer.setInterval(1000)
                self.timer.timeout.connect(self.update_time)

        def update_time(self):
                qdt = QDateTime.currentDateTime()
                str_dt, time = qdt.toString("yyyy-MM-dd hh:mm:ss").split(" ")
                h, m, s = time.split(":")
                self.date_lable.setText(str_dt)
                self.time_label.setText(time)
                self.hourRing.setValue(int(h))
                self.minRing.setValue(int(m))
                self.secRing.setValue(int(s))

        def ui_init(self):
                self.setMaximumSize(QSize(400, 280))
                self.setFixedHeight(280)
                self.setMinimumWidth(350)
                self.layout = QVBoxLayout()
                self.layout.setSpacing(5)
                self.hourRing = ProgressRing(self)
                self.hourRing.setMinimum(0)
                self.hourRing.setMaximum(24)
                self.hourRing.setStrokeWidth(10)

                hour_layout = QVBoxLayout(self.hourRing)
                self.minRing = ProgressRing(self.hourRing)
                self.minRing.setMinimum(0)
                self.minRing.setMaximum(60)
                self.minRing.setStrokeWidth(10)
                hour_layout.addWidget(self.minRing)
                hour_layout.setAlignment(self.minRing, Qt.AlignCenter)

                min_layout = QVBoxLayout(self.minRing)
                self.secRing = ProgressRing(self.minRing)
                self.secRing.setMinimum(0)
                self.secRing.setMaximum(60)
                self.secRing.setStrokeWidth(10)
                self.hourRing.setCustomBarColor("#0033FF", "#3366FF")
                self.minRing.setCustomBarColor("#009900", "#66CC66")
                self.hourRing.setFixedSize(QSize(150, 150))
                self.minRing.setFixedSize(QSize(120, 120))
                self.secRing.setFixedSize(QSize(90, 90))
                min_layout.addWidget(self.secRing)
                min_layout.setAlignment(self.secRing, Qt.AlignCenter)

                self.date_lable = BodyLabel(self)
                hover_layout = QVBoxLayout(self.secRing)
                self.time_label = BodyLabel(self.secRing)
                hover_layout.addWidget(self.time_label)
                hover_layout.setAlignment(self.time_label, Qt.AlignCenter)

                self.layout.addWidget(self.hourRing)
                self.layout.addWidget(self.date_lable)
                self.layout.setAlignment(self.hourRing, Qt.AlignCenter)
                self.layout.setAlignment(self.date_lable, Qt.AlignCenter)
                self.setLayout(self.layout)

if __name__ == '__main__':
        QApplication.setHighDpiScaleFactorRoundingPolicy(
        Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
        QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
        QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
        app = QApplication(sys.argv)
        w = dateTime_panel()
        w.show()
        app.exec_()


免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
^^峫尐゛. + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

idk666 发表于 2024-8-2 18:18
6,有创意
liyan1022 发表于 2024-8-2 20:30
chenxingfeng 发表于 2024-8-3 08:18
liyan1022 发表于 2024-8-3 09:41

那个大神有时间把他本地化就好了
 楼主| 999CWCR999 发表于 2024-8-5 14:13
liyan1022 发表于 2024-8-2 20:30
https://neverup7.github.io/notion.clock/
看看这个

太秀了66666
hollywu 发表于 2024-8-29 17:12
liyan1022 发表于 2024-8-2 20:30
https://neverup7.github.io/notion.clock/
看看这个

太好看了,这个,可以发一下吗,大佬
HR741158 发表于 2024-9-3 11:17
学习,收藏备用
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-12-1 07:04

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表