An example of pyqt5 using label control to display time in real time

Time:2020-2-10

As follows:

import sys
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class showTime(QDialog):
  def __init__(self):

    super(showTime, self).__init__()
    self.resize(500, 400)
    Self.setwindowtitle ("label display time")
    self.label = QLabel(self)
    self.label.setFixedWidth(200)
    self.label.move(90, 80)
    self.label.setStyleSheet("QLabel{background:white;}"
                   "Qlabel {color: rgb (300300300120); font size: 10px; font weight: bold; font family: Tahoma;}"
                   )
    #Dynamic display time on the label
    timer = QTimer(self)
    timer.timeout.connect(self.showtime)
    timer.start()
  def showtime(self):
    datetime = QDateTime.currentDateTime()
    text = datetime.toString()
    self.label.setText("   "+ text)

if __name__ == '__main__':
  app = QtWidgets.QApplication(sys.argv)
  my = showTime()
  my.show()
  sys.exit(app.exec_())

The above example of pyqt5 using label control to display time in real time is all the content that Xiaobian shared with you. I hope it can give you a reference, and I hope you can support developepaer more.