79507838

Date: 2025-03-13 23:11:34
Score: 1
Natty:
Report link

You could try using a lambda function when binding your button:

new_card.clicked.connect(lambda _, x=card: self.click_card(x))

def click_card(self, card):
    print(f"I am {card}")

You need to be carefull with lambda function inside a for loop, that's why I've put x=card. The argument _ is just a placeholder for the regular argument to the "clicked" signal

https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QAbstractButton.html#PySide2.QtWidgets.PySide2.QtWidgets.QAbstractButton.clicked

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Geneviève Le Houx