我无法从列表中创建标签
我有一个列表,我想在pyqt5设计器上的标签中显示所有列表。但是,事实证明,仅弹出列表中的最后一项
list_of_stall = ["McDonalds", "Italian Cuisine", "Mini Wok", "Japanese", "Subway", "Malay Food"]
number = ["stall1","stall2","stall3","stall4","stall5","stall6"]
class Ui_MainWindow(object):
def makeLabel(self,label,i,j):
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40 + 160*i,40 + 190*j , 581, 61))
font = QtGui.QFont()
font.setPointSize(14)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName(label)
for i in range(3):
for j in range(2) :
makeLabel(self,number[i],i,j)
def retranslateUi(self, MainWindow):
def printLabel(self,label,i):
self.label.setText(_translate("MainWindow", list_of_stall[i]))
for i in range(x) :
printLabel(self,number[i],i)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())