python3.x+pyqt5实现主窗口状态栏里(嵌入)显示进度条功能
作者:higher80 时间:2021-12-29 06:55:13
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实现主窗口状态栏里(嵌入)显示进度条功能,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/higher80/article/details/82703532
标签:python,pyqt5,进度条
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pygame Rect区域位置的使用(图文)
2023-08-14 05:27:48
![](https://img.aspxhome.com/file/2023/5/77585_0s.gif)
教你使用SQL Server数据库进行网络链接
2009-01-13 13:41:00
Python matplotlib的spines模块实例详解
2021-10-11 06:37:58
![](https://img.aspxhome.com/file/2023/9/110189_0s.jpg)
python format 格式化输出方法
2023-12-24 16:26:19
python实现通过代理服务器访问远程url的方法
2023-03-14 00:47:38
用python实现五子棋实例
2022-08-23 21:42:38
![](https://img.aspxhome.com/file/2023/8/65908_0s.jpg)
带你深入了解数据库设计中的英文术语表
2008-12-09 14:53:00
python 基于TCP协议的套接字编程详解
2023-09-11 21:09:30
Django中信号signals的简单使用方法
2023-08-18 08:49:49
JS实现六边形3D拖拽翻转效果的方法
2023-08-28 15:51:31
![](https://img.aspxhome.com/file/2023/8/56218_0s.png)
Python实现手写一个类似django的web框架示例
2022-06-18 03:17:26
![](https://img.aspxhome.com/file/2023/9/65049_0s.png)
python使用cookielib库示例分享
2022-09-22 13:53:37
python 多线程中子线程和主线程相互通信方法
2021-05-13 03:56:44
如何实现全文检索?
2010-05-24 18:24:00
让ExtJs的combobox不显示HTML……
2009-05-31 17:01:00
jquery AJAX 三个发送状态 posting, error, success
2010-07-31 18:59:00
速记Python布尔值
2022-04-23 10:02:17
Mootools 1.2教程(10)——Fx.Tween的使用
2008-12-02 18:03:00
用Python制作检测Linux运行信息的工具的教程
2022-03-01 17:49:15
PyCharm配置anaconda环境的步骤详解
2023-07-26 10:11:20
![](https://img.aspxhome.com/file/2023/1/105561_0s.jpg)