我在pyqt中生成带有for循环的list长度函数的按钮。每个按钮具有与目录相对应的不同文本。问题是,当用户单击按钮时,我不知道如何检索目录。
if len(self.cartella) > 1:
self.Dialog = QtWidgets.QDialog()
self.ui = Ui_Dialog()
self.ui.setupUi(self.Dialog)
self.lista = []
for j in range(0,len(self.cartella)):
self.lista.append(j)
for i in range(0,len(self.cartella)):
self.lista[i] = QtWidgets.QPushButton(self.ui.verticalWidget)
self.lista[i].setObjectName("bottone3")
self.lista[i].setStyleSheet("#bottone3:hover{\n"
"\n"
"background-color:blue;\n"
"color:white;\n"
"border-radius: 8px;\n"
"\n"
"\n"
"\n"
"}\n"
"#bottone3{\n"
"border:None;}")
self.lista[i].setText(self.cartella[i])
self.ui.verticalLayout.addWidget(self.lista[i])
self.lista[i].clicked.connect(self.finricerca)
self.file = Excel(self.cartella[i])
self.file.import_rig_col("Sheet1")