• 大小: 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)


评论

共有 条评论