i want to create multiple buttons in Tkinter, in a for loop. The problem is that I'm iterating through a dataframe (the values in the rows are the content of the Tkinter gadets I'm creating) with .iterrows which means, I have no "i", only rows and index.
The problem is, that as I'm creating the buttons and give them different commands with lambda i:i=SomeFunction(somevariable), and here I have to use a variable other than "i". The result is that the commands are all referring at the end for to the last value of this "somevariable" and not to the value of it as it was at the creation of the button.
import tkinter
def printout(somevariable):
print(somevariable)
window = tkinter.Tk()
i = 0
somevariable = 0
for index, rows in enumerate(["a","b","c","d"]):
b = tkinter.Button(window,
text=rows,
command= lambda i=i: printout(somevariable))
b.pack()
somevariable = somevariable + 1
window.mainloop()
And all the buttons are containing as command the very last value of the "somevariable".
Any idea how to make this work??