I am making a simple program that creates a 3x3 matrix of tkinter.Button()
and when a button is pressed it should display the "Clicked" text on it.
But the result seems like buttons that lie on the same column get bound to the same command - the one that targets the button of the last row of that column.
from tkinter import *
root = Tk()
text = [[None]*3]*3
buttons = [[None]*3]*3
def action(i, j):
text[i][j].set('Clicked')
for i in range(3):
for j in range(3):
text[i][j] = StringVar()
text[i][j].set('(%d, %d)' % (i,j))
buttons[i][j] = Button(root, command = lambda i=i, j=j : action(i, j))
buttons[i][j].config(textvariable = text[i][j], width = 9, height = 5)
buttons[i][j].grid(row = i, column = j)
root.mainloop()