Python PyQt5模塊實(shí)現(xiàn)窗口GUI界面代碼實(shí)例
PyQt5是基于Digia公司強(qiáng)大的圖形程式框架Qt5的python接口,由一組python模塊構(gòu)成。PyQt5本身?yè)碛谐^(guò)620個(gè)類和6000函數(shù)及方法。在可以運(yùn)行于多個(gè)平臺(tái),包括:Unix, Windows, and Mac OS。
代碼如下
from PyQt5.QtWidgets import QApplication,QWidget,QProgressBar,QPushButtonfrom PyQt5.QtCore import QBasicTimerfrom PyQt5.QtGui import QIconimport 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è)置進(jìn)度條位置及大小 self.btn = QPushButton(’開(kāi)始’, self) self.btn.move(50, 90) self.btn.clicked.connect(self.doAction) #點(diǎn)擊按鈕時(shí)執(zhí)行的動(dòng)作函數(shù)指定為self.doAction() # self.btn.setGeometry(50, 90, 40, 25) self.timer = QBasicTimer() #構(gòu)建一個(gè)計(jì)數(shù)器 self.step = 0 #設(shè)置基數(shù) self.setGeometry(300, 300, 280, 170) # 設(shè)置整個(gè)窗體的大小 self.setWindowTitle(’進(jìn)度條’) #設(shè)置窗口標(biāo)題 # self.setWindowIcon(’logo2.png’) #設(shè)置窗口圖標(biāo) 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每次重圍時(shí)將self.step 賦值給pbar def doAction(self): if self.timer.isActive(): self.timer.stop() self.btn.setText(’開(kāi)始’) else: self.timer.start(100, self) self.btn.setText(’停止’) if __name__ == ’__main__’: app = QApplication(sys.argv) # 創(chuàng)建一個(gè)QT應(yīng)用對(duì)象 ex = Example() sys.exit(app.exec_())
結(jié)果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)2. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?3. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算4. ASP.Net MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼5. jstl 字符串處理函數(shù)6. JSP動(dòng)態(tài)網(wǎng)頁(yè)開(kāi)發(fā)原理詳解7. PHP中為什么使用file_get_contents("php://input")接收微信通知8. .Net core Blazor+自定義日志提供器實(shí)現(xiàn)實(shí)時(shí)日志查看器的原理解析9. IOS蘋果AppStore內(nèi)購(gòu)付款的服務(wù)器端php驗(yàn)證方法(使用thinkphp)10. XML CDATA是什么?
