import sys from PySide2.QtWidgets import QApplication, QVBoxLayout, QPushButton, QWidget app = QApplication(sys.argv) window = QWidget() layout = QVBoxLayout() button1 = QPushButton("Button 1") button2 = QPushButton("Button 2") button3 = QPushButton("Button 3") layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3) layout.setMargin(20) window.setLayout(layout) window.show() sys.exit(app.exec_())
import sys from PySide2.QtWidgets import QApplication, QVBoxLayout, QLabel, QLineEdit, QWidget app = QApplication(sys.argv) window = QWidget() layout = QVBoxLayout() label = QLabel("Enter your name:") lineedit = QLineEdit() layout.addWidget(label) layout.addWidget(lineedit) layout.setMargin(5) window.setLayout(layout) window.show() sys.exit(app.exec_())This example creates a simple layout with a QLabel and a QLineEdit. We set the margin to 5 pixels to reduce the amount of space around the widgets. This creates a more compact layout: Overall, PySide2 is a powerful package library for creating GUIs in Python, and the QVBoxLayout layout is a versatile tool for arranging widgets in a vertical direction.