垂直布局和水平布局的参数调用情况是一致的
VBoxLayout.py
""" 垂直盒布局(QVBoxLayout) """ import sys, math from PyQt5.QtWidgets import * class VBoxLayout(QWidget): def __init__(self): super(VBoxLayout, self).__init__() self.setWindowTitle("水平盒布局") hlayout = QVBoxLayout() hlayout.addWidget(QPushButton('按钮1')) hlayout.addWidget(QPushButton('按钮2')) hlayout.addWidget(QPushButton('按钮3')) hlayout.addWidget(QPushButton('按钮4')) hlayout.addWidget(QPushButton('按钮5')) #设置按钮的间距 hlayout.setSpacing(20) self.setLayout(hlayout) if __name__ == "__main__": app = QApplication(sys.argv) main = VBoxLayout() main.show() sys.exit(app.exec_())