-- 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("水平布局管理例子")
# 水平布局按照從左到右的順序進行添加按鈕部件粗梭。
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)
# 水平布局按照從左到右的順序進行添加按鈕部件拗军。
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_())