I have a couple of widgets that will be connected to a single function which required extra arguments.
I found that I can use a lambda function in place to pass the function some arguments.
The problem is the arguments are getting replaced in the loop and the lambda function is passing only the last one set.
Heres what I got:
self.widgets is a dictinary with keys for the group of buttons, to make it short let's say it have 2 buttons[QToolButton], linked to their keys: 'play' and 'stop'.
def connections(self):
for group in self.widgets:
self.widgets[group].clicked.connect(lambda: self.openMenu(group))
def openMenu(self,group):
print group
But no matter what button I click, it will always print the same group, the last that was iterate in the for loop.
Any way to fix this?