class MyDialog(Ui_validateIdentityUI): def __init__(self, parent=None): super(MyDialog, self).__init__(parent) # 调用内部的 setupUi() ,本身对象作为参数 self.setupUi(self) # 连接 QPushButton 的点击信号到槽 BigWork() self.pushButton.clicked.connect(self.validate_excel) self.pushButton_2.clicked.connect(self.stop_validate) def validate_excel(self): try: #把按钮禁用掉 self.pushButton.setDisabled(True) #import 自己的进程类 from threads import BigWorkThread #新建对象,传入参数 filePath = self.lineEdit.text() print(filePath) houzui = "" if len(filePath) > 0: list = filePath.split('/') zui = list[len(list) - 1] houzui = zui.split(".") if houzui[1] != "xlsx": raise Exception("文件类型不正确!") result_name = houzui[0] + "_" + "校验结果" + "." + houzui[1] path = "" for i in range(len(list) - 1): path += list[i] + "\\" inpath = path + zui exportFilePath = path + result_name print(inpath) print(exportFilePath) self.bwThread = BigWorkThread(int(1), inpath, exportFilePath, True) # 连接子进程的信号和槽函数 self.bwThread.finishSignal.connect(self.callbacklog) # 开始执行 run() 函数里的内容 self.bwThread.start() else: self.setTextBrowser("文件路径不能为空") self.pushButton.setDisabled(False) except Exception as err: self.pushButton.setDisabled(False) self.setTextBrowser("校验失败!错误描述:" + str(err)) #增加形参准备接受返回值 ls def callbacklog(self, ls): #使用传回的返回值 for word in ls: self.setTextBrowser( time.strftime("%Y/%m/%d %H:%M", time.localtime()) + " " + word) print( time.strftime("%Y/%m/%d %H:%M", time.localtime()) + " " + word) #恢复按钮 self.pushButton.setDisabled(False) def stop_validate(self): # 把按钮禁用掉 self.pushButton_2.setDisabled(True) self.bwThread.stop() self.pushButton_2.setDisabled(False)