I want to create buttons after some processing according to the results, and I want them to be clickable.
Here's what I tried :
for action in actions:
name = action[2]
button = QPushButton(name, self.timelineFrame)
dir = "actions/{}.mp4".format(name)
button.move(...)
button.clicked.connect(lambda: self.OpenVid(dir))
button.show()
The self.OpenVid function opens a video with VLC.
The problem is that every button opens the same video, the last one in the list of actions. As if button.clicked.connect had overwritten every buttons from previous loops.
I've tried using self.button and renamed them like this at the end of each loop:
rename_attribute(self, "button", "button_{}".format(name))
With the function :
def rename_attribute(object_, old_attribute_name, new_attribute_name):
setattr(object_, new_attribute_name, getattr(object_, old_attribute_name))
delattr(object_, old_attribute_name)
But I got the same results : self.button.clicked.connect still seems to rewrite the other buttons even if they have different names.