I'm making simple UI in Python using , in which I have 5 similar buttons with different labels on. To make code a little shorter I created buttons in loop like this:
self.btntext = ["-10mm", "-1mm", "Stop", "+1mm", "+10mm"]
self.ctrButtons = []
for i in self.btntext:
self.ctrButtons.append(tk.Button(self.buttonFrame, text=i, command= lambda: self.addSubtract(i)))
I thought that it would pass current button text to addSubtract function but instead it always passes the last element of btntext.
Why it works like this? And can I make this work without adding 5 buttons individually?