1# first we need to import QVBoxLayout, QWidget from PyQt5.QtWidgets
2import sys
3from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, \
4 QPushButton, QVBoxLayout
5# you can copy and run this code
6class MainWindow(QMainWindow):
7 def __init__(self, parent=None):
8 super(MainWindow, self).__init__(parent)
9
10 layout = QVBoxLayout()
11 btn = QPushButton("Click")
12
13 layout.addWidget(btn) # add the widget to our layout
14
15 w = QWidget()
16 w.setLayout(layout) # set layout to our central widget
17 self.setCentralWidget(w) # set w as central widget
18 self.show()
19
20if __name__ == "__main__":
21 app = QApplication(sys.argv)
22 window = MainWindow()
23 sys.exit(app.exec_())