from PyQt5.QtWidgets import QApplication, QLineEdit, QWidget app = QApplication([]) widget = QWidget() line_edit = QLineEdit() widget.setLayout(QVBoxLayout()) widget.layout().addWidget(line_edit) widget.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QLineEdit, QLabel, QWidget, QVBoxLayout app = QApplication([]) widget = QWidget() line_edit = QLineEdit() label = QLabel('Enter your name:') layout = QVBoxLayout() widget.setLayout(layout) layout.addWidget(label) layout.addWidget(line_edit) widget.show() app.exec_()This example uses QLineEdit with a QLabel to create a form-like layout. The user enters their name into the QLineEdit and the QLabel provides context for the input field. The two widgets are added to a QVBoxLayout before the widget is shown. Overall, PyQt5.QtWidgets QLineEdit is a useful widget for creating input fields in PyQt5 applications.