0

I'm working in a battleship game in python 2.7 with Tkinter, but i have a little issue. I want that when i press a button in my grid, it change the background, but with my code, when i press whatever button, the only one that change is the last one (index 99) Here's a screenshot of the grid Image 1

from Tkinter import *

def positioningShips(matrixButtons, button):
    if button == None:
        for i in range(100):
            matrixButtons[i].config(command= lambda: positioningShips(matrixButtons, matrixButtons[i]))
    else:
       button.config(bg="black")

def grid(gridWindow):
    row1 = 1
    column1 = 1
    matrixButtons = []
    for i in range(100):
        matrixButtons.append(Button(gridWindow,text="",width=6,height=3))
        matrixButtons[i].grid(row= row1,column= column1)
        matrixButtons[i].config(bg="steel blue", command= lambda:  positioningShips(matrixButtons, None))
        if column1%10==0 and column1 != 1:
            row1+=1
            column1 = 1
        else:
            column1+=1

def Battleship():
    gridWindow = Tk()
    gridWindow.title("Battleship")
    gridWindow.resizable(0,0)
    grid(gridWindow)
    gridWindow.mainloop()  

if __name__ == "__main__":
    Battleship()

Hope you can help me guys.

pd: I can't use class in this.

0 Answers0