您可以使用循环来创建多个QLabel,然后将它们添加到您想要的布局中。这里是一个示例代码:
import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabelclass MyWidget(QWidget):def __init__(self):super().__init__()self.initUI()def initUI(self):layout = QVBoxLayout()for i in range(5):label = QLabel("Label {}".format(i))layout.addWidget(label)self.setLayout(layout)self.show()if __name__ == '__main__':app = QApplication(sys.argv)widget = MyWidget()sys.exit(app.exec_())在上面的例子中,我们创建了一个QWidget并使用QVBoxLayout作为其布局。然后,我们使用循环创建了5个QLabel,并将它们添加到布局中。最后,我们设置了该布局为QWidget的布局,并显示了该窗口。
这将创建一个窗口,其中包含5个标签,每个标签的文本为"Label n",其中n是从0到4的数字。

