所有代码:
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 newdef adder():global iglobal angle_s, angle_m, angle_hi += 1angle_s += 6if angle_s == 360:angle_s = 0angle_m = i / 10angle_h = i / 120if angle_m == 360:angle_m = 0if angle_h == 360:angle_h = 0i = 0if __name__ == '__main__':app = QApplication(sys.argv)form = uic.loadUi('clock.ui') # 导入uiform.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 = 0angle_s = 0angle_m = 0angle_h = 0timer = 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_())