I've been trying to create row of buttons(using tkinter) and asign to them the command using for loop. Also storing those buttons in array. I was unable to pass the command with different to each button, after last irritation it seems like it affected every button and I don't understand why. Anyone notices what's the problem?
import tkinter as tk
root = tk.Tk()
week_days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
for i in range(len(week_days)):
week_days[i] = tk.Button(root, text=week_days[i], command=lambda: buttons_func(i), font=("Arial", 12), width=4)
week_days[i].grid(row=1, column=i, padx=3)
def buttons_func(n):
week_days[n].configure(text="Foo")
root.mainloop()
I tried to do this without for loop and everything woorks. In for loop it looks like with every irritation command changes for every button in array when changing only one. Thought that it may be that the i takes out same space in memory after every irritation but then the text of the button is not changed like the command.