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 实现提取log文件中的关键句子,并进行统计分析

利用python开发了一个提取sim.log 中的各个关键步骤中的时间并进行统计的程序: #!/usr/bin/python2.6 import re,datetime file_n...

如何在python中实现随机选择

这篇文章主要介绍了如何在python中实现随机选择,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 想从一个序列中随机抽取若干元素,或者...

利用Python演示数型数据结构的教程

使用 Python 内建的defaultdict 方法可以轻松定义一个树的数据结构。 简单的说树也可以是一个字典数据结构   def tree(): return def...

Python中使用PyQt把网页转换成PDF操作代码实例

代码很简单,功能也很简单 =w= webpage2pdf #!/usr/bin/env python3 import sys try: from PyQt4 import...

Python FTP操作类代码分享

复制代码 代码如下:#!/usr/bin/py2# -*- coding: utf-8 -*-#encoding=utf-8 '''''    ftp自动下...