Hello,
The textbox component is a very common basic component.
It is simple to use. I will show the usage from the QPlainTextEdit class in the PyQt5 library.
Some methods
setPlainText("message")
content message
move(X,Y)
the point to be positioned.
resize(width,height)
width and height values
An example:
Creator textbox method
def textboxcreate(self): self.textbox = QPlainTextEdit(self) self.textbox.move(150,25) self.textbox.resize(75, 25)
And writer method
def writetextbox(self): self.textbox.setPlainText("test")
Result:
Full code
from PyQt5 import QtWidgets from PyQt5.QtWidgets import QApplication, QMainWindow, QPlainTextEdit import sys W_WIDTH = 400 W_HEIGHT = 250 W_X = 400 W_Y = 150 # button creator class class CreateButton: def __init__(self, window, text, width, height, x, y): self.button = QtWidgets.QPushButton(window) self.button.setText(text) self.button.resize(width, height) self.button.move(x, y) def get_instance(self): return self.button class MainFrame(QMainWindow): def __init__(self): super(MainFrame, self).__init__() self.init() self.show() def writetextbox(self): self.textbox.setPlainText("test") def textboxcreate(self): self.textbox = QPlainTextEdit(self) self.textbox.move(150,25) self.textbox.resize(75, 25) def init(self): self.resize(W_WIDTH, W_HEIGHT) self.move(W_X, W_Y) self.setWindowTitle("www.langpy.com | Python GUI Tutorial") self.button_question = CreateButton(self, "Write to textbox", 120, 40, 10, 10).get_instance() self.textboxcreate() self.button_question.clicked.connect(self.writetextbox) app = QApplication(sys.argv) win = MainFrame() sys.exit(app.exec_())