You can get user input with a QLineEdit widget. In this lesson you’ll make a line edit that changes a labels text when run.
A window can contain one or more QLineEdit widgets. They do not contain a label themselves, for UX purposes you may want to add a label to the QLineEdit to tell the user what to type in the box.
PyQt Desktop Apps with Python
The object oriented code below creates a window with the constructor. An input box or line edit is added to the window, this is called a QLineEdit.
Then it adds a label and a line edit:
self.lineEntry = QLineEdit(self)
self.qlabel = QLabel(self)
You can connect every keypress in the input box (QLineEdit) with a method call.
In that method set the labels text and adjust the labels size.
def onChanged(self, text):
Copy and paste the example code below to try it yourself: