Source code

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton , QGridLayout

def window():
app = QApplication(sys.argv)
win = QWidget()

grid = QGridLayout()

grid.addWidget(QPushButton("Button 1") , 0 , 0)
grid.addWidget(QPushButton("Button 2") , 1 , 0)
grid.addWidget(QPushButton("Button 3") , 0 , 1)
grid.addWidget(QPushButton("Button 4") , 1 , 1)
grid.addWidget(QPushButton("Button 5") , 0 , 2)
grid.addWidget(QPushButton("Button 6") , 1 , 2)
grid.addWidget(QPushButton("Button 7") , 2 , 0)
grid.addWidget(QPushButton("Button 8") , 2 , 1)
grid.addWidget(QPushButton("Button 9") , 2 , 2)

win.setLayout(grid)

win.setWindowTitle("PyQt Grid Layout")
win.setGeometry(50,50,400,200)
win.show()
sys.exit(app.exec_())

if __name__ == '__main__':
window()

Younes Derfoufi
my-courses.net

Leave a Reply