-
大小: 9KB文件類型: .py金幣: 1下載: 0 次發布日期: 2021-05-14
- 語言: Python
- 標簽: subprocess??
資源簡介
PyQt5中異步刷新UI和Python中的多線程總結
學習python和PyQt5的過程中,做了demo,可以從電腦端向手push文件和安裝apk的GUIdemo,初學者可從這個例子中學到很多知識。涉及到PyQt5中異步刷新UI+Python中的多線程+python中使用subprocess。可結合我的博客學習https://blog.csdn.net/u013247461/article/details/85063455
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
#?Autho:chenghao?Albert?Time:2018/12/17
#?-*-?coding:?utf-8?-*-
#?Autho:chenghao?Albert?Time:2018/12/10
import?sys
import?tkinter.messagebox
import?tkinter?as?tk
import?tkinter
import?threading
import?subprocess
from?PyQt5?import?QtCore?QtGui?QtWidgets
from?PyQt5.QtWidgets?import?QMessageBox
from?PyQT_Form?import?Ui_MainWindow
class?MyPyQT_Form(QtWidgets.QMainWindow?Ui_MainWindow):
????def?__init__(self?parent=None):
????????super(MyPyQT_Form?self).__init__(parent)
????????self.setupUi(self)
????????#?self.retranslateUi(self)
????????self.pushButton.clicked.connect(self.pushButton_click)
????????self.pushButton_help.clicked.connect(self.softHelp)
????????self.pushButton_about.clicked.connect(self.softAbout)
????????self.thread?=?AnalysisLogThread()
????????#?開始按鈕按下后使其不可用,啟動線程
????????self.thread.sinOut.connect(self.showMsg_1)
????????self.thread.enablepb.connect(self.enablePushButton)
????????self.thread.setpb.connect(self.setProcessBarValue)
????????self.thread.popmsg.connect(self.popMessageBox)
????def?closeEvent(self?event):??#?關閉窗口觸發以下事件
????????reply?=?QMessageBox.question(self?‘title‘?‘Are?you?sure?to?qiut?‘?QMessageBox.Yes?|?QMessageBox.No?QMessageBox.No)
????????if?reply?==?QMessageBox.Yes:
????????????event.accept()?#接受關閉事件
????????else:
????????????event.ignore()?#忽略關閉事件
????def?softHelp(self):
????????QMessageBox.information(self?“HELP“??‘?This?tool?is?used?to?import?resources?and?install?apk?for?testing.‘)
????def?softAbout(self):
????????QMessageBox.information(self‘ABOUT‘?‘For?internal?use?only?by?Sagereal?please?do?not?spread?without?authorization!‘
?????????????????????????????????????????????‘\n?‘
?????????????????????????????????????????????‘\n?Author??:??chenghao‘
?????????????????????????????????????????????‘\n?Mail??:??chenghao@sagereal.com?‘
?????????????????????????????????????????????‘\n?Org???:??Sagereal??‘
?????????????????????????????????????????????‘\n?Team??:??Automation?‘
?????????????????????????????????????????????‘\n?Version?:??V001?‘
?????????????????????????????????????????????‘\n?Date?:?2018-12-17‘)
????def?showMsg_1(self?str):
????????print(“call?showMsg_1()“)
????????print(str)
????????self.listWidget.addItem(str)
????def?enablePushButton(self):
????????self.pushButton.setEnabled(True)
????#?實現pushButton_click()函數,textEdit是我們放上去的文本框的id
????def?pushButton_click(self):
????????self.listWidget.clear()
????????self.progressBar.setProperty(“value“?0)
????????self.pushButton.setEnabled(False)
????????self.thread.start()
????def?setProcessBarValue(selfnum):
????????self.progressBar.setProperty(“value“?num)
????def?popMessageBox(self?str):
????????reply?=?QMessageBox.information(self?‘Prompt‘?str)
class?AnalysisLogThread(QtCore.QThread):
????sinOut?=?QtCore.pyqtSignal(str)
????enablepb?=?QtCore.pyqtSignal()
????setpb=?QtCore.pyqtSignal(int)
????popmsg=?QtCore.pyqtSignal(str)
- 上一篇:一加云服務照片批量導出 Python爬蟲
- 下一篇:python遺傳算法 源代碼
評論
共有 條評論