python3.x+pyqt5實(shí)現(xiàn)主窗口狀態(tài)欄里(嵌入)顯示進(jìn)度條功能
1、代碼1:
(1)進(jìn)度條等顯示在主窗口狀態(tài)欄的右端,代碼如下:
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('準(zhǔn)備中...') self.progressBar = QProgressBar() self.label = QLabel() self.label2 = QLabel() self.label.setText("正在計(jì)算: ") self.label2.setText("正在計(jì)算: ") 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) # 設(shè)置進(jìn)度條的范圍 self.progressBar.setValue(100) if __name__ == '__main__': app = QApplication(sys.argv) main2 = SampleBar() main2.show() sys.exit(app.exec_())
(2)實(shí)現(xiàn)的界面如下圖1紅框:
圖1
2、代碼2:
(1)進(jìn)度條等顯示在主窗口狀態(tài)欄的左端,代碼如下:
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('準(zhǔn)備') self.progressBar = QProgressBar() self.pushbutton = QPushButton("點(diǎn)這里") self.label = QLabel() self.label2 = QLabel() self.label.setText("開始計(jì)算 ") self.label2.setText("正在計(jì)算: ") # 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) # 設(shè)置進(jìn)度條的范圍 self.progressBar.setValue(20) if __name__ == '__main__': app = QApplication(sys.argv) main2 = SampleBar() main2.show() sys.exit(app.exec_())
2)實(shí)現(xiàn)的界面如下圖2紅框:
總結(jié)
以上所述是小編給大家介紹的python3.x+pyqt5實(shí)現(xiàn)主窗口狀態(tài)欄里(嵌入)顯示進(jìn)度條功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
在Python中操作列表之list.extend()方法的使用
這篇文章主要介紹了在Python中操作列表之list.extend()方法的使用,是Python入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-05-05Python時(shí)間差中seconds和total_seconds的區(qū)別詳解
今天小編就為大家分享一篇Python時(shí)間差中seconds和total_seconds的區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12python爬蟲實(shí)現(xiàn)POST request payload形式的請(qǐng)求
這篇文章主要介紹了python爬蟲實(shí)現(xiàn)POST request payload形式的請(qǐng)求,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04python實(shí)現(xiàn)測(cè)試工具(一)——命令行發(fā)送get請(qǐng)求
這篇文章主要介紹了python如何實(shí)現(xiàn)命令行發(fā)送get請(qǐng)求,幫助大家更好的利用python進(jìn)行測(cè)試工作,感興趣的朋友可以了解下2020-10-10Python中staticmethod和classmethod的作用與區(qū)別
今天小編就為大家分享一篇關(guān)于Python中staticmethod和classmethod的作用與區(qū)別,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10Python檢測(cè)一個(gè)對(duì)象是否為字符串類的方法
這篇文章主要介紹了Python檢測(cè)一個(gè)對(duì)象是否為字符串類的方法,即檢測(cè)是一個(gè)對(duì)象是否是字符串對(duì)象,本文還講解了一個(gè)有趣的判斷方法,需要的朋友可以參考下2015-05-05通過(guò)python讀取txt文件和繪制柱形圖的實(shí)現(xiàn)代碼
這篇文章主要介紹了通過(guò)python讀取txt文件和繪制柱形圖的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03python實(shí)現(xiàn)簡(jiǎn)易淘寶購(gòu)物
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡(jiǎn)易淘寶購(gòu)物,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11