构造水平布局, 在水平布局上添加按钮,同时调节了按钮之间的间距
HBoxLayout.py
""" 水平盒布局(QHBoxLayout) """ import sys, math from PyQt5.QtWidgets import * class HBoxLayout(QWidget): def __init__(self): super(HBoxLayout, self).__init__() self.setWindowTitle("水平盒布局") hlayout = QHBoxLayout() hlayout.addWidget(QPushButton('按钮1')) hlayout.addWidget(QPushButton('按钮2')) hlayout.addWidget(QPushButton('按钮3')) hlayout.addWidget(QPushButton('按钮4')) hlayout.addWidget(QPushButton('按钮5')) #设置按钮的间距 hlayout.setSpacing(100) self.setLayout(hlayout) if __name__ == "__main__": app = QApplication(sys.argv) main = HBoxLayout() main.show() sys.exit(app.exec_())