我在函数中使用toPlainText(),但它不返回值
此函数应返回在QtextEdit中输入的值
def buscar(self):
var = self.RUNP.toPlainText()
for pid in psutil.pids():
listapid = psutil.Process(pid)
if listapid.name() == var:
pass
self.RUNP.clear()
return var
我需要使用函数返回的值在csv文件中进行搜索。
以下是一些代码:
from PyQt5 import QtCore, QtGui, QtWidgets
import psutil
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(371, 134)
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(140, 20, 104, 21))
self.textEdit.setObjectName("textEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(140, 60, 113, 32))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
dat = self.pushButton.clicked.connect(lambda: self.buscar())
self.pushButton.setText(dat)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "PushButton"))
def buscar(self):
var = self.textEdit.toPlainText()
for pid in psutil.pids():
listapid = psutil.Process(pid)
if listapid.name() == var:
pass
self.textEdit.clear()
return var
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())