這篇文章主要講解了Python中PyQt5模塊實現(xiàn)窗口GUI界面的方法,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。

PyQt5是基于Digia公司強大的圖形程式框架Qt5的python接口,由一組python模塊構(gòu)成。PyQt5本身擁有超過620個類和6000函數(shù)及方法。在可以運行于多個平臺,包括:Unix, Windows, and Mac OS。
代碼如下
from PyQt5.QtWidgets import QApplication,QWidget,QProgressBar,QPushButton
from PyQt5.QtCore import QBasicTimer
from PyQt5.QtGui import QIcon
import sys
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI() # 顯示窗體內(nèi)容
def initUI(self):
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 50, 200, 25) #設(shè)置進度條位置及大小
self.btn = QPushButton('開始', self)
self.btn.move(50, 90)
self.btn.clicked.connect(self.doAction) #點擊按鈕時執(zhí)行的動作函數(shù)指定為self.doAction()
# self.btn.setGeometry(50, 90, 40, 25)
self.timer = QBasicTimer() #構(gòu)建一個計數(shù)器
self.step = 0 #設(shè)置基數(shù)
self.setGeometry(300, 300, 280, 170) # 設(shè)置整個窗體的大小
self.setWindowTitle('進度條') #設(shè)置窗口標題
# self.setWindowIcon('logo2.png') #設(shè)置窗口圖標
self.show()
def timerEvent(self, *args, **kwargs):
if self.step >= 100:
self.timer.stop()
self.btn.setText('完成')
return
self.step += 1
self.pbar.setValue(self.step) #timer每次重圍時將self.step 賦值給pbar
def doAction(self):
if self.timer.isActive():
self.timer.stop()
self.btn.setText('開始')
else:
self.timer.start(100, self)
self.btn.setText('停止')
if __name__ == '__main__':
app = QApplication(sys.argv) # 創(chuàng)建一個QT應(yīng)用對象
ex = Example()
sys.exit(app.exec_())
網(wǎng)站欄目:Python中PyQt5模塊實現(xiàn)窗口GUI界面的方法-創(chuàng)新互聯(lián)
文章地址:http://chinadenli.net/article16/cejhgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站維護、企業(yè)網(wǎng)站制作、關(guān)鍵詞優(yōu)化、Google、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容