from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QGridLayout app = QApplication([]) window = QWidget() layout = QGridLayout() layout.addWidget(QLabel('Label 1'), 0, 0) layout.addWidget(QLabel('Label 2'), 0, 1) layout.addWidget(QPushButton('Button 1'), 1, 0) layout.addWidget(QPushButton('Button 2'), 1, 1) window.setLayout(layout) window.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout app = QApplication([]) window = QWidget() widgets = [QPushButton(f'Button {i}') for i in range(1, 6)] layout = QGridLayout() for i, widget in enumerate(widgets): layout.addWidget(widget, i // 2, i % 2) num_rows = (len(widgets) + 1) // 2 layout.setRowStretch(num_rows, 1) window.setLayout(layout) window.show() app.exec_()Package Library: The package library for PyQt5.Qt QGridLayout is the PyQt5 library, which is a Python binding to the Qt GUI toolkit. It provides a complete set of bindings to the Qt library, allowing you to write full-featured GUI applications using Python instead of C++. The PyQt5.Qt QGridLayout is just one of many classes that are available in the PyQt5.QtWidgets module, which provides a rich set of GUI widgets for building PyQt5 applications.