圆月山庄资源网 Design By www.vgjia.com

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红框:

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

                                                                                           图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实现主窗口状态栏里(嵌入)显示进度条功能

总结

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

标签:
python,pyqt5,python,主窗口,python,状态栏,进度条

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com