1

I'm making a GUI application using Tkinter.

I have a loop going over an array: each iteration it makes a button with a specific command. The problem is: each iteration, Python keeps reference to the index (which is an object of the class "Option" this class holds the command for each button). This results in all buttons doing the same thing.

How do I make each button do a different thing?

Thanks for your help

Code:

    i = 0
    length = len(options)
    for t in options:
        btn = Button(win, text=t.buttonText)
        btn.grid(row=1, column=c, columnspan=1, sticky=N+S+E+W)
        btn.configure(bg='black', fg='white', borderwidth=0, font=font, command=lambda: optionCommand(t.nextStageIndex, t.action))
        i += 1```
Kasper103
  • 11
  • 1

0 Answers0