首先看下实现效果:
下面是代码:
import sys
import time
from PyQt4 import QtCore, QtGui
#继承QThread
class TimerThread(QtCore.QThread):
    timeout_signal = QtCore.pyqtSignal(int)
    def __init__(self):
        QtCore.QThread.__init__(self)
    #重写run方法
    def run(self):
      self.timeout_signal.emit(0)
      while True:
        for i in range(1,5):
            print("定时器计数 = ", i)
            time.sleep(1)
            #发送timeout信号
            self.timeout_signal.emit(i)
        break
      print("定时器线程已退出...")
class MyApp(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self, None)
        #设置窗口位置
        self.setGeometry(200, 250, 800, 70)
        #设置窗口标题
        self.setWindowTitle('PyQt线程定时器演示')
        #水平布局
        self.layout = QtGui.QHBoxLayout()
        #进度条
        self.pbar = QtGui.QProgressBar()
        #进度条最大值
        self.pbar.setMaximum(4)
        #设置布局
        self.layout.addWidget(self.pbar)
        self.setLayout(self.layout)
    #槽函数,接收timeout信号
    def slog_timeout(self, i):
        self.pbar.setValue(i)
if __name__ == '__main__':
  app = QtGui.QApplication(sys.argv)
  test = MyApp()
  tThread = TimerThread()
  #信号槽绑定
  tThread.timeout_signal.connect(test.slog_timeout)
  tThread.start()
  test.show()
  app.exec_()
文章的脚注信息由WordPress的wp-posturl插件自动生成

 
                 微信扫一扫,打赏作者吧~
微信扫一扫,打赏作者吧~ 
	![[整理]how to run flask with pyqt5](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/03/pyqt_flask.png&w=280&h=210&zc=1)
![[已解决]LINK : fatal error LNK1158: cannot run 'rc.exe' 错误的解决办法](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/02/Snipaste_2021-02-17_15-18-26-1024x505.png&w=280&h=210&zc=1)
![[已解决]Python扩展模块 error: Unable to find vcvarsall.bat](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/11/Snipaste_2020-11-19_10-01-38.png&w=280&h=210&zc=1)
![[整理]PyQt画圆,动态变色](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/08/drawCircle.gif&w=280&h=210&zc=1)
