I want to populate a menu dynamically with pyqt5. I am looping all actions and adding them in one by one, this does populate the menu just right, however, all the actions are connected to the last slot function. So even if I select item 1
, the console print is item 3
. Below is a snippet of my code:
menu = QMenu()
items = ['item 1', 'item 2', 'item 3']
for item in items:
self.menu.addAction(item, lambda: self.printMe(item))
def printMe(self, text):
print(text, "selected")