from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout # create the application and window app = QApplication([]) window = QWidget() # create the vertical layout layout = QVBoxLayout() # add a button to the layout button = QPushButton("Click me") layout.addItem(button) # set the layout for the window window.setLayout(layout) # show the window window.show() # run the application app.exec_()
from PySide2.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout # create the application and window app = QApplication([]) window = QWidget() # create the vertical layout layout = QVBoxLayout() # add multiple labels to the layout label1 = QLabel("First label") layout.addItem(label1) label2 = QLabel("Second label") layout.addItem(label2) label3 = QLabel("Third label") layout.addItem(label3) # set the layout for the window window.setLayout(layout) # show the window window.show() # run the application app.exec_()This example creates a window with three labels added to a vertical layout using the addItem method. Package library: PySide2.