PyQt5 布局

 import sys

 from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QVBoxLayout, QHBoxLayout, QPushButton, QGridLayout

 class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
vlayout = QVBoxLayout() # 垂直布局 hlayout = QHBoxLayout() # 水平布局 for i in range(10): # 十个标签
lab1 = QLabel("label" + str(i), self)
# lab1.move(15, 10 + (i * 30))
hlayout.addWidget(lab1)
vlayout.addLayout(hlayout) # 水平布局添加到垂直布局中 for i in range(10): # 十个标签
lab1 = QLabel("label" + str(i), self)
# lab1.move(15, 10 + (i * 30))
vlayout.addWidget(lab1) self.setLayout(vlayout) self.setGeometry(100, 100, 300, 600)
self.setWindowTitle("定位测试")
self.show() class Test(QWidget):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
okButton = QPushButton("确定")
cancelButton = QPushButton("取消")
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton) vbox = QVBoxLayout()
vbox.addStretch(1)
vbox.addLayout(hbox) self.setLayout(vbox)
self.setGeometry(100, 100, 500, 500)
self.show() class gridLayout(QWidget):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
grid = QGridLayout()
self.setLayout(grid)
names = ['Cls', 'Bck', '', "Close",
"", "", "", "/",
"", "", "", "*",
"", "", "", "-",
"", ".", "=", "+"]
positions = [(i, j) for i in range(5) for j in range(4)]
for position, name in zip(positions, names):
if name == "":
continue
button = QPushButton(name)
grid.addWidget(button, *position)
label = QLabel("计算器计算器计算器计算器计算器计算器计算器计算器计算器计算器计算器计算器计算器计算器");
grid.addWidget(label, 5, 0, 1, 4) # 夸四列
lab1 = QLabel("计算器1")
grid.setSpacing(10)
grid.addWidget(lab1, 9, 0, 4, 1) # 夸四行
self.move(300, 150)
self.setWindowTitle("计算器")
self.show() if __name__ == '__main__':
app = QApplication(sys.argv)
# ex = Example()
# t = Test()
c = gridLayout()
sys.exit(app.exec_())
上一篇:响应式WEB设计的基本原则大总结


下一篇:支撑大规模公有云的Kubernetes改进与优化 (1)