I have a 3x3 grid of buttons, all of which are bound to the same event funciton. This function changes the labels of particular buttons, based on which button was clicked. I want to be able to choose which buttons will be effected by looking at where they fall on the grid, i.e. row and column values.
For example, I want to be able to say "considering the button clicked was on (row 1, column 2), I want to change the labels of the buttons on (row 2, column 0) and (row 1, column 1).
I know how to find the row and column of the button which was clicked:
import tkinter
def click(event):
space = event.widget
space_label = space['text']
row = space.grid_info()['row'] #get the row of clicked button
column = space.grid_info()['column'] #get the column of clicked button
board = tkinter.Tk()
for i in range(0,9): #creates the 3x3 grid of buttons
button = tkinter.Button(text = "0")
if i in range(0,3):
r = 0
elif i in range(3,6):
r = 1
else:
r = 2
button.grid(row = r, column = i%3)
button.bind("<Button-1>",click)
board.mainloop()
But I can't figure out how to access a button's label given only a row and column of the grid.
P.S. new to coding, sorry if this is obvious, i looked around but couldn't find any similar enough questions.