I have nine buttons created like so:
MyButton1 = Button(game, text="BUTTON1", image=pixel, compound="c", width=200, height=200, command=callback(1))
MyButton1.grid(row=0, column=0)
MyButton2 = Button(game, text="BUTTON2", image=pixel, compound="c", width=200, height=200, command=callback(2))
MyButton2.grid(row=1, column=0)
MyButton3 = Button(game, text="BUTTON3", image=pixel, compound="c", width=200, height=200, command=callback(3))
MyButton3.grid(row=2, column=0)
# and so on
I want to change the text of a particular button when it is clicked, and I know that button.config can be used to change some things about the button. For example, if I wanted to change the text for MyButton1, I could do something like this: MyButton1.config(text="X"). But I think it would be quite messy to have a different function for the command for each button, so I could create a function like this:
def callback(id):
print(id)
# change the text of the button
But, my problem is that I don't know how to access the button when the button I am trying to get differs each time. I can't do "MyButton" + str(id).config, for obvious reasons (it's a string). So how should I do this?


