import sys from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QLineEdit, QGridLayout class Window(QWidget): def __init__(self): super().__init__() # Create the widgets label1 = QLabel("Label 1") label2 = QLabel("Label 2") button1 = QPushButton("Button 1") button2 = QPushButton("Button 2") edit = QLineEdit() # Create the layout grid = QGridLayout() # Add the widgets to the layout grid.addWidget(label1, 0, 0) grid.addWidget(label2, 0, 1) grid.addWidget(button1, 1, 0) grid.addWidget(button2, 1, 1) grid.addWidget(edit, 1, 2) # Set the layout for the window self.setLayout(grid) # Create the application app = QApplication(sys.argv) # Create the window window = Window() window.show() # Run the event loop sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout class Window(QWidget): def __init__(self): super().__init__() # Create the buttons button1 = QPushButton("Button 1") button2 = QPushButton("Button 2") button3 = QPushButton("Button 3") button4 = QPushButton("Button 4") # Create the layout grid = QGridLayout() # Add the buttons to the layout grid.addWidget(button1, 0, 0) grid.addWidget(button2, 0, 1) grid.addWidget(button3, 1, 0) grid.addWidget(button4, 1, 1) # Set the size of the cells grid.setRowMinimumHeight(0, 100) grid.setRowMinimumHeight(1, 100) grid.setColumnMinimumWidth(0, 100) grid.setColumnMinimumWidth(1, 100) # Set the layout for the window self.setLayout(grid) # Create the application app = QApplication(sys.argv) # Create the window window = Window() window.show() # Run the event loop sys.exit(app.exec_())In conclusion, Python PyQt5.Qt QGridLayout is a package library that provides a simple, easy-to-use layout manager for arranging widgets in a grid-based structure. By using this library, you can create responsive and versatile desktop applications with a flexible and dynamic user interface.