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實現主窗口狀態欄里(嵌入)顯示進度條功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

