S
S
sverhderjawa2021-08-18 10:46:20
PyQt
sverhderjawa, 2021-08-18 10:46:20

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)


The program ends with an error:
Process finished with exit code -1073740791 (0xC0000409)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bazik29, 2021-08-21
@Bazik29

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 question

Ask a Question

731 491 924 answers to any question