python3.x+pyqt5实现主窗口状态栏里(嵌入)显示进度条功能

yipeiwu_com6年前Python基础

1、代码1:

(1)进度条等显示在主窗口状态栏的右端,代码如下:

from PyQt5.QtWidgets import QMainWindow, QProgressBar, QApplication, QLabel
import sys
class SampleBar(QMainWindow):
  """Main Application"""
  def __init__(self, parent = None):
    print('Starting the main Application')
    super(SampleBar, self).__init__(parent)
    self.initUI()
  def initUI(self):
    # Pre Params:
    self.setMinimumSize(800, 600)
    # File Menus & Status Bar:
    self.statusBar().showMessage('准备中...')
    self.progressBar = QProgressBar()
    self.label = QLabel()
    self.label2 = QLabel()
    self.label.setText("正在计算: ")
    self.label2.setText("正在计算: ")
    self.statusBar().addPermanentWidget(self.label)
    self.statusBar().addPermanentWidget(self.label2)
    self.statusBar().addPermanentWidget(self.progressBar)
    # self.statusBar().addWidget(self.progressBar)
    # This is simply to show the bar
    self.progressBar.setGeometry(0, 0, 100, 5)
    self.progressBar.setRange(0, 500) # 设置进度条的范围
    self.progressBar.setValue(100)
if __name__ == '__main__':
  app = QApplication(sys.argv)
  main2 = SampleBar()
  main2.show()
  sys.exit(app.exec_())

(2)实现的界面如下图1红框:

                                                                                           图1

2、代码2:

(1)进度条等显示在主窗口状态栏的左端,代码如下:

from PyQt5.QtWidgets import QMainWindow, QProgressBar, QApplication, QLabel, \
  QStatusBar, QPushButton
import sys
class SampleBar(QMainWindow):
  """Main Application"""
  def __init__(self, parent = None):
    # print('Starting the main Application')
    super(SampleBar, self).__init__(parent)
    self.initUI()
  def initUI(self):
    # Pre Params:
    self.setMinimumSize(800, 600)
    # File Menus & Status Bar:
    self.statusBar = QStatusBar()
    self.statusBar.setStyleSheet('QStatusBar::item {border: none;}')
    self.setStatusBar(self.statusBar)
    self.statusBar.showMessage('准备')
    self.progressBar = QProgressBar()
    self.pushbutton = QPushButton("点这里")
    self.label = QLabel()
    self.label2 = QLabel()
    self.label.setText("开始计算 ")
    self.label2.setText("正在计算: ")
    # self.statusBar.addWidget(self.label, 0)
    self.statusBar.addPermanentWidget(self.label, stretch=2)
    self.statusBar.addPermanentWidget(self.label2, stretch=0)
    self.statusBar.addPermanentWidget(self.progressBar, stretch=4)
    # self.statusBar().addWidget(self.progressBar)
    # This is simply to show the bar
    # self.progressBar.setGeometry(0, 0, 100, 5)
    self.progressBar.setRange(0, 500) # 设置进度条的范围
    self.progressBar.setValue(20)
if __name__ == '__main__':
  app = QApplication(sys.argv)
  main2 = SampleBar()
  main2.show()
  sys.exit(app.exec_())

2)实现的界面如下图2红框:

总结

以上所述是小编给大家介绍的python3.x+pyqt5实现主窗口状态栏里(嵌入)显示进度条功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

python实现WebSocket服务端过程解析

python实现WebSocket服务端过程解析

一种类似Flask开发的WebSocket-Server服务端框架,适用python3.X 1、安装模块Pywss pip install pywss 2、搭建简易服务器 2....

对Python定时任务的启动和停止方法详解

在python中我们可以使用APScheduler进行定时任务。 APScheduler的具体编码这里就不介绍了。主要说下在终端中启动和停止任务。 一、运行计划任务的python脚本...

Python中for循环控制语句用法实例

Python中for循环控制语句用法实例

本文实例讲述了Python中for循环控制语句用法。分享给大家供大家参考。具体分析如下: 第一个:求 50 - 100 之间的质数 import math for i in ran...

web.py 十分钟创建简易博客实现代码

一、web.py简介 web.py是一款轻量级的Python web开发框架,简单、高效、学习成本低,特别适合作为python web开发的入门框架。官方站点:http://webpy....

在Python中使用PIL模块处理图像的教程

在Python中使用PIL模块处理图像的教程

PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了。PIL功能非常强大,但API却非常简单易用。 安装PIL 在Debian/Ubunt...