import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton class MyWidget(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout() self.setLayout(layout) button1 = QPushButton("Button 1") layout.addWidget(button1) layout.addSpacing(10) # add 10 pixels of vertical space button2 = QPushButton("Button 2") layout.addWidget(button2) if __name__ == '__main__': app = QApplication(sys.argv) widget = MyWidget() widget.show() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton class MyWidget(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout() self.setLayout(layout) label = QLabel("Enter your name:") layout.addWidget(label) line_edit = QLineEdit() layout.addWidget(line_edit) layout.addSpacing(20) # add 20 pixels of vertical space button = QPushButton("Submit") layout.addWidget(button) if __name__ == '__main__': app = QApplication(sys.argv) widget = MyWidget() widget.show() sys.exit(app.exec_())In this example, we create a layout that includes a label, a text input box, and a button. We add some vertical space between the text input box and the button using the addSpacing method.