from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout from PyQt5.QtCore import Qt app = QApplication([]) window = QWidget() layout = QVBoxLayout() button = QPushButton('Click me!') layout.addWidget(button) layout.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) window.setLayout(layout) window.show() app.exec_()In this example, we create a QVBoxLayout and add a QPushButton to it. We then call setAlignment() and pass in the AlignmentFlag.AlignHCenter and AlignmentFlag.AlignVCenter options to center the button both horizontally and vertically within the layout. Finally, we set the layout for the window and display it. Package library: PyQt5 by Riverbank Computing.