49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Sun Sep 29 21:35:04 2024
|
|
|
|
@author: wxb51
|
|
"""
|
|
|
|
import sys
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QLineEdit, QPushButton
|
|
|
|
class Example(QWidget):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
self.initUI()
|
|
|
|
def initUI(self):
|
|
# 创建一个垂直布局
|
|
self.verticalLayout = QVBoxLayout()
|
|
|
|
# 创建一个放置布局的小部件
|
|
self.layoutWidget = QWidget(self)
|
|
|
|
# 循环创建水平布局、文本输入框和按钮
|
|
for i in range(21): # 从0到20
|
|
horizontalLayout = QHBoxLayout()
|
|
horizontalLayout.setObjectName(f"horizontalLayout_{i}")
|
|
|
|
lineEdit = QLineEdit(self.layoutWidget)
|
|
lineEdit.setObjectName(f"lineEdit_{i}")
|
|
horizontalLayout.addWidget(lineEdit)
|
|
|
|
pushButton = QPushButton(self.layoutWidget)
|
|
pushButton.setObjectName(f"pushButton_{i}")
|
|
horizontalLayout.addWidget(pushButton)
|
|
|
|
self.verticalLayout.addLayout(horizontalLayout)
|
|
|
|
# 将垂直布局设置为主布局
|
|
self.setLayout(self.verticalLayout)
|
|
|
|
# 设置窗口标题
|
|
self.setWindowTitle('Multiple Layouts Example')
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication(sys.argv)
|
|
ex = Example()
|
|
ex.show()
|
|
sys.exit(app.exec_()) |