首页
学习
活动
专区
圈层
工具
发布

python pyqt5 QHBoxLayout 水平布局

-- coding: utf-8 --

""" 【简介】 水平布局管理例子

"""

import sys from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton

class Winform(QWidget): def init(self, parent=None): super(Winform, self).init(parent) self.setWindowTitle("水平布局管理例子")

代码语言:javascript
复制
    # 水平布局按照从左到右的顺序进行添加按钮部件。
    hlayout = QHBoxLayout()
    hlayout.addWidget(QPushButton(str(1)))
    hlayout.addWidget(QPushButton(str(2)))
    hlayout.addWidget(QPushButton(str(3)))
    hlayout.addWidget(QPushButton(str(4)))
    hlayout.addWidget(QPushButton(str(5)))
    self.setLayout(hlayout)

if name == "main": app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())


-- coding: utf-8 --

""" 【简介】 水平布局管理例子

"""

import sys from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton from PyQt5.QtCore import Qt

class Winform(QWidget): def init(self, parent=None): super(Winform, self).init(parent) self.setWindowTitle("水平布局管理例子") self.resize(800, 200)

代码语言:javascript
复制
    # 水平布局按照从左到右的顺序进行添加按钮部件。
    hlayout = QHBoxLayout()

    # 水平居左 垂直居上
    hlayout.addWidget(QPushButton(str(1)), 0, Qt.AlignLeft | Qt.AlignTop)
    hlayout.addWidget(QPushButton(str(2)), 0, Qt.AlignLeft | Qt.AlignTop)
    hlayout.addWidget(QPushButton(str(3)))
    # 水平居左 垂直居下
    hlayout.addWidget(QPushButton(str(4)), 0, Qt.AlignLeft | Qt.AlignBottom)
    hlayout.addWidget(QPushButton(str(5)), 0, Qt.AlignLeft | Qt.AlignBottom)

    self.setLayout(hlayout)

if name == "main": app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())

下一篇
举报
领券