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实现感知机线性分类模型示例代码

python实现感知机线性分类模型示例代码

前言 感知器是分类的线性分类模型,其中输入为实例的特征向量,输出为实例的类别,取+1或-1的值作为正类或负类。感知器对应于输入空间中对输入特征进行分类的超平面,属于判别模型。 通过梯度...

解决tensorflow测试模型时NotFoundError错误的问题

错误代码如下: NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor...

python matplotlib库绘制散点图例题解析

python matplotlib库绘制散点图例题解析

假设通过爬虫你获取到了北京2016年3,10月份每天白天的最高气温(分别位于列表a,b),那么此时如何寻找出气温随时间(天)变化的某种规律? a = [11,17,16,11,12,11...

python中enumerate的用法实例解析

在python中enumerate的用法多用于在for循环中得到计数,本文即以实例形式向大家展现python中enumerate的用法。具体如下: enumerate参数为可遍历的变量,...

pytorch使用Variable实现线性回归

pytorch使用Variable实现线性回归

本文实例为大家分享了pytorch使用Variable实现线性回归的具体代码,供大家参考,具体内容如下 一、手动计算梯度实现线性回归 #导入相关包 import torch as...