I do not understand what type of structure is matrix, but I think it is equivalent to a list of dictionaries.
The problem is that you must pass as an argument to the lambda function assigning it, the clicked signal takes as a parameter a Boolean value that indicates that if the button is checked or not (by default this property is disabled so that this value is false), you must add another parameter.
class App(QMainWindow):
def launch(self, filepath):
subprocess.run(filepath)
def __init__(self):
super(App, self).__init__()
matrix = [{"path": "path1", "setIcon": "icon1", "posx": 0, "posy": 0},
{"path": "path2", "setIcon": "icon2", "posx": 0, "posy": 150},
{"path": "path3", "setIcon": "icon3", "posx": 0, "posy": 300}]
for value in matrix:
filepath = value['path']
icon = value['setIcon']
posx = value['posx']
posy = value['posy']
btn = QToolButton(self)
btn.setIcon(QIcon(icon))
btn.setIconSize(QSize(64, 64))
btn.resize(100, 100)
btn.move(posx, posy)
btn.clicked.connect(lambda checked, arg=filepath: self.launch(arg))
self.initUI()
def initUI(self):
self.setGeometry(150, 150, 1250, 650)
self.setWindowTitle('LinuxLauncher')
self.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…