ive tried to find a solution, but could not find the one that works. I have a 2d list of tkinter buttons, and I want to change their text when I click. I tried to do this:
def create_board(number): print(number) for i in range (0,number): buttonList.append([]) for j in range(0,number): print(i,j) buttonList[i].append(Button(root, text = " ", command = lambda: update_binary_text(i,j))) buttonList[i][j].pack()
Then, when it is clicked, it calls this function:
def update_binary_text(first,second): print(first,second) buttonList[first][second]["text"] = "1"
When I press the button, it just doesnβt do anything, I had a program showing the indices of the button the button was pressed on and they ALL show 4, 4 (this is when the number of variables = 5) Is there a solution for this?
this is my first python attempt for a class.
thanks
source share