0

I want to something like this:

list = [0,1,2,3,4]
for x in range(len(list)):
    hi = tk.Button(command = lambda: function)
def function():
    print(list[x])

The problem is x is always 5 so it always prints 4, I want it to print the corresponding value. Is there any way to do this?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Binding an argument default (as in the duplicate) with get you separate values bound for each `lambda`. – ShadowRanger Jul 31 '20 at 23:52
  • You'll also have to modify the `def function` to accept the argument value that will now be passed (instead of using the global `x`). – martineau Jul 31 '20 at 23:55

0 Answers0