QPlainTextEdit is a multiline text area in PyQt. To set the text, we use its method insertPlainText(). We can set its position and size using the methods move() and resize().
Related course:
Textarea The example below creates a text area using PyQt5.
We will create the usual QMainWindow to add the widget to. It is just for plain text, like notepad. To add new lines we add the \n character.
import sysfrom PyQt5.Qt import QApplication, QClipboardfrom PyQt5 import QtCore, QtWidgetsfrom PyQt5.QtWidgets import QMainWindow, QWidget, QPlainTextEditfrom PyQt5.QtCore import QSizeclass ExampleWindow (QMainWindow) : def __init__ (self) : QMainWindow.__init__(self) self.setMinimumSize(QSize(440 , 240 )) self.setWindowTitle("PyQt5 Textarea example" ) self.b = QPlainTextEdit(self) self.b.insertPlainText("You can write text here.\n" ) self.b.move(10 ,10 ) self.b.resize(400 ,200 ) if __name__ == "__main__" : app = QtWidgets.QApplication(sys.argv) mainWin = ExampleWindow() mainWin.show() sys.exit( app.exec_() )