1

Basically, I am not sure why any button I click only updates the text from the last button from the list. I do believe I am passing in the correct button from the list, but perhaps I am forgetting about something.

"""
# This creates and returns the game board as a list. New Button
# elements are created and displayed to the user using the
# wrapper for each new button.
#
# return - a list of wrapped button widgits
"""
def CreateBoard():
    temp_board = []#the board for the game
    
    j=0 #column
    for i in range(9):#'i' is the row
        new_btn = Button(root,text=" ", padx=50, pady=50)
        temp_board.append(UIWrapper(new_btn, 1, i%3, j))
        new_btn.grid(row=(i%3), column=j)
        temp_board[i].widget.configure(command= lambda:AddMove(temp_board[i].widget))
        if (i+1)%3 == 0: j+=1 #update column

    #return the newly created list
    return temp_board

"""
# Adds a marker to the button, which is just updating the text
# of the button.
#
# @param the button widget
"""
def AddMove(btn):
    if btn['text'] == " ":
        btn.configure(text="X")   

The UIWrapper is just the widget, screen, row, column, where screen is just an integer.

The end result is the following image:

enter image description here

Any help is appreciated.

0 Answers0