0

I have a class that I want to create multiple buttons using Tkinter. Every button will have a command with a function that will have different parameters for every iteration. The buttons will be saved in a list for later use.

The problem is that the function in every button takes in the parameter of the iteration from the last loop.

I have tried something like this: `

lst_buttons = []
for i in range(1,6):
    lst_buttons.append(Button(window, commmand=lambda: function(i)))

` window: is the window that the buttons will be displayed in. Is there any way to save the buttons in the list with them getting function(1), function(2), ... function(5) using a for loop, or do i need to write them separately?

0 Answers0