Tag: qt

pyqt textarea

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().

pyqt text area

Related course:
Create Simple GUI Applications with Python and Qt


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.

# PyQt5 text area

import sys
from PyQt5.Qt import QApplication, QClipboard
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QPlainTextEdit
from PyQt5.QtCore import QSize

class ExampleWindow(QMainWindow):
def __init__(self):

self.setMinimumSize(QSize(440, 240))
self.setWindowTitle("PyQt5 Textarea example")

# Add text field
self.b = QPlainTextEdit(self)
self.b.insertPlainText("You can write text here.\n")

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = ExampleWindow()
sys.exit( app.exec_() )