How to read from QTextedit in python?

If all you need is the displayed text in your QTextEdit widget, you can access that by using the toPlainText() method on the widget you need the text from.

Example:

mytext = self.textEdit.toPlainText()

At this point, you can do whatever you want with mytext. You can write it to a file, you can manipulated it, etc.

If you need to (re)populate your QTextEdit with the modified value of mytext, you can do that by using setPlainText

self.textEdit.setPlainText(mytext)

To write the string to a file, you’ll do something like this:

with open('somefile.txt', 'a') as f:
    f.write(mytext)

This will append mytext to somefile.txt

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)