资源简介

pyqt5做一个一个时钟demo,这个程序七十行代码,实现了一个时钟的效果,用到了python中的QPainter、多线程,数学中的坐标、三角函数等知识。

资源截图

代码片段和文件信息

import sys
import datetime
import math
from PyQt5.QtWidgets import QWidget QApplicationQPushButton
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import time
from threading import Thread

class Example(QWidgetThread):
    def __init__(self):
        super(  ).__init__(  )
        self.pos_x=5
        self.pos_y=5
        self.live=True
        self.initUI()

    def initUI(self):
        self.text = “aadsafa“
        self.setGeometry(300 300 320 320)
        self.setWindowtitle(‘时钟‘)
        self.show()
        t=Thread( target=self.refreshTimeShow )
        t.start()
    def refreshTimeShow(self):
        while self.live  :
            now =  datetime.datetime.now()
            hour = now.hour + now.minute/60
            min  = now.minute + now.second/60
            sec = now.second
            print(now)
            self.hourP0 self.hourP1 = self.getHourNeedlePoint(hour1090)
            self.minuteP0self.minuteP1 = self.getMinuteOrSecondNeedlePoint(min10120)
            self.secondP0self.secondP1 = self.getMinuteOrSecondNeedlePoint( sec10150 )
            self.update()
            time.sleep(0.5)
    def paintEvent(self event):
        print(‘paintEventpaintEventpaintEventpaintEventpaintEventpaintEvent‘)
        qp = QPainter( )
        qp.begin(self)
        pen = QPen(Qt.red 3 Qt.SolidLine)
        qp.setPen(pen)
        qp.drawLine( self.hourP0self.hourP1  )
        qp.drawLine(self.hourP1 self.hourP0)
      

评论

共有 条评论