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的函数嵌套的使用方法

例子:复制代码 代码如下:def re_escape(fn):    def arg_escaped(this, *args):  &n...

基于Python和PyYAML读取yaml配置文件数据

基于Python和PyYAML读取yaml配置文件数据

一、首先我们需要安装 PyYAML 第三方库 直接使用 pip install PyYAML 就可以(这里我之前是装过的,所以提示我PyYAML已经在这个目录下了,是5.1.2版本的)...

Python输出\u编码将其转换成中文的实例

Python输出\u编码将其转换成中文的实例

爬取了下小猪短租的网站出租房信息但是输出的时候是这种: 百度了下。python2.7在window上的编码确实是个坑 解决如下 如果是个字典的话要先将其转成字符串 导入json库 然后...

python在windows和linux下获得本机本地ip地址方法小结

本文实例总结了python在windows和linux下获得本机本地ip地址方法。分享给大家供大家参考。具体分析如下: python的socket包含了丰富的函数和方法可以获得本机的ip...

详解python uiautomator2 watcher的使用方法

该方是基于uiautomator2如下版本进行验证的: PS C:\windows\system32> pip show uiautomator2 Name: uiautoma...