PYQT制作动态时钟

所有代码:

python 复制代码
import sys
from PyQt5.QtCore import Qt, QTimer, QRect
from PyQt5.QtGui import QPixmap, QTransform, QPainter, QImage
from PyQt5.QtWidgets import QApplication, QLabel
from PyQt5 import uic
import new


def adder():
    global i
    global angle_s, angle_m, angle_h
    i += 1
    angle_s += 6
    if angle_s == 360:
        angle_s = 0
        angle_m = i / 10
        angle_h = i / 120
        if angle_m == 360:
            angle_m = 0
        if angle_h == 360:
            angle_h = 0
            i = 0


if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = uic.loadUi('clock.ui')  # 导入ui
    form.show()

    form.label_second.setAlignment(Qt.AlignCenter)
    form.label_minute.setAlignment(Qt.AlignCenter)
    form.label_hour.setAlignment(Qt.AlignCenter)

    # 加载并设置图片
    image_second = QPixmap("second300")
    form.label_second.setPixmap(image_second)
    image_minute = QPixmap("minute300")
    form.label_minute.setPixmap(image_minute)
    image_hour = QPixmap("hour300")
    form.label_hour.setPixmap(image_hour)

    i = 0
    angle_s = 0
    angle_m = 0
    angle_h = 0

    timer = QTimer()
    timer.start(100)
    timer.timeout.connect(adder)
    timer.timeout.connect(lambda: form.label_second.setPixmap(image_second.transformed(QTransform().rotate(angle_s))))
    timer.timeout.connect(lambda: form.label_minute.setPixmap(image_minute.transformed(QTransform().rotate(angle_m))))
    timer.timeout.connect(lambda: form.label_hour.setPixmap(image_hour.transformed(QTransform().rotate(angle_h))))

    sys.exit(app.exec_())
相关推荐
智购科技自动售卖机厂家1 天前
2026自动售货机OTA升级系统设计:从全量升级到差分升级的带宽优化工程实践~YH
大数据·人工智能·numpy·pyqt·fastapi
【赫兹威客】浩哥1 天前
【无标题】
python·spring·django·pyqt
小灰灰搞电子3 天前
PyQt QTextBoundaryFinder类详解:精准定位文本边界
pyqt
小灰灰搞电子4 天前
PyQt 实现自己的桌面萌宠源码分享
pyqt
小灰灰搞电子8 天前
PyQt6 QCommandLineParser 类详解:命令行参数解析实战指南
pyqt·参数解析
微小冷9 天前
pyQT中的文本部件及其区别
pyqt·gui·富文本编辑器·文本输入框·文本浏览器
房开民13 天前
PyQt 翻译(国际化)极简讲解
pyqt
房开民18 天前
PyQt5 常用模块(对应Qt五大模块)
数据库·pyqt
懷淰メ21 天前
【AI赋能】基于PyQt+YOLO+DeepSeek水上漂浮物检测系统(详细介绍)
人工智能·yolo·目标检测·计算机视觉·pyqt·漂浮物·水上漂浮物
龙腾AI白云1 个月前
【多Agent系统的倒U型曲线与前瞻治理】
人工智能·plotly·pyqt·知识图谱