Answer the question
In order to leave comments, you need to log in
How to pass text from plainTextEdit to PyQt as a function parameter?
I have created a plainTextEdit text field and a button. When the button is clicked, the text entered by the user must be passed to the parse() function and the function must be executed. With the function itself, everything is fine. Here is the code:
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget) # поле для ввода текста
self.txt = self.plainTextEdit.toPlainText() # беру текст из поля
self.pushButton.clicked.connect(lambda: self.parse(self.txt)) # обработка нажатия на кнопку
def parse(self, city):
print(city)
Answer the question
In order to leave comments, you need to log in
Get the text from the field inside the parse method, for example:
class A(QWidget):
def __init__(self):
super().__init__()
self.plainTextEdit = QPlainTextEdit(self)
self.pushButton = QPushButton(self)
self.pushButton.clicked.connect(self.parse)
def parse(self):
txt = self.plainTextEdit.toPlainText()
print(txt)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question