I really don't understand this.. The text of y is fine but when it is passed into the lambda function to print y it just prints 2.
It seems simple yet I don't get it.
Could someone explain or tell me how I can fix this?
Thanks
from tkinter import *
window = Tk()
buttonHeight = 10
buttonWidth = 25
gridItemsList = [['-', '-', '-'], ['-', '-', '-'],['-', '-', '-']]
for y in range (0, 3):
for x in range(0, 3):
gridItemsList[2-y][x] = ([Button(window, height=buttonHeight, width=buttonWidth, background="white", text=y, command=lambda:print(y)), [] ])
gridItemsList[2-y][x][0].grid(column = y, row=x, padx=20, pady=20)
mainloop()