pyqt5 使用label控件实时显示时间的实例

yipeiwu_com5年前Python基础

如下所示:

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显示时间")
    self.label = QLabel(self)
    self.label.setFixedWidth(200)
    self.label.move(90, 80)
    self.label.setStyleSheet("QLabel{background:white;}"
                   "QLabel{color:rgb(300,300,300,120);font-size:10px;font-weight:bold;font-family:宋体;}"
                   )
    # 动态显示时间在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_())

以上这篇pyqt5 使用label控件实时显示时间的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python实现图像识别功能

本文实例为大家分享了python实现图像识别的具体代码,供大家参考,具体内容如下 #! /usr/bin/env python from PIL import Image...

Python3的高阶函数map,reduce,filter的示例详解

函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数。 注意其中:map和filter返回一个惰性序列,可迭代对象,需要转化为list >&...

Python跑循环时内存泄露的解决方法

Python跑循环时内存泄露的解决方法

Python跑循环时内存泄露 今天在用Tensorflow跑回归做测试时,仅仅需要循环四千多次 (补充说一句,我在个人PC上跑的)。运行以后,我就吃饭去了。等我回来后,Console窗口...

Python读取网页内容的方法

本文实例讲述了Python读取网页内容的方法。分享给大家供大家参考。具体如下: import urllib2 #encoding = utf-8 class Crawler: d...

python创建只读属性对象的方法(ReadOnlyObject)

复制代码 代码如下:def ReadOnlyObject(**args):    dictBI = {}    args_n...