from PySide6.QtWidgets import QWidget, QApplication, QFileDialog from Ui_文件或文本框提取答案 import Ui_Form import os from database_tools_2 import * class MyWindow_tqda(QWidget,Ui_Form): def __init__(self): super().__init__() self.setupUi(self) self.bind() def bind(self): self.radioButton_text.setChecked(True) self.textlayout() self.radioButton_text.clicked.connect(self.textlayout) self.radioButton_file.clicked.connect(self.filelayout) self.pushButton_selectfilepath.clicked.connect(self.selectfilepath) self.pushButton_exec.clicked.connect(self.exec) def textlayout(self): self.pushButton_selectfilepath.setDisabled(True) self.lineEdit_filepath.setDisabled(True) self.plainTextEdit_rawString.setEnabled(True) def filelayout(self): self.pushButton_selectfilepath.setEnabled(True) self.lineEdit_filepath.setEnabled(True) self.plainTextEdit_rawString.setDisabled(True) def selectfilepath(self): self.filepath = QFileDialog.getOpenFileName(self,"选择.tex文件",os.getcwd(),"tex文件(*.tex);;所有文件(*)")[0] self.lineEdit_filepath.setText(self.filepath) def exec(self): if self.radioButton_text.isChecked(): data = self.plainTextEdit_rawString.toPlainText() else: data = ReadTextFile(self.filepath) print(self.lineEdit_2.text()) anslist = generateAnswerList(data,self.lineEdit_2.text()) output = "ans\n\n" for id,ans in anslist: if not ans == "暂无答案": output += f"{id}\n{ans}\n\n" self.plainTextEdit_ans.setPlainText(output) if __name__ == '__main__': app = QApplication([]) windows = MyWindow_tqda() windows.show() app.exec()