I wanted to create a game called "battleship". For this, I have to allow the user to place his ships.
I wanted to try this by allowing the user to color a field where the ship has to be placed. My problem is, that I have created 15 x 15 variables in a list by using 2 for loops. Is there actually a command possibility to for example get the row and the column of the grid, because this part, for example, will always give me the last i
and the last j
I have asked for. Otherwise, I would have to create 225 lines,
by mentioning the i
and j
when using lambda
.
self.ship[i][j] = tk.Button(root, text="", padx=30, pady=20, command=lambda:color(i,j))
self.ship[i][j].grid(row=i, column=j)