I am using a nested for loop to draw a grid of 10 rows of rectangles and 10 columns of rectangles (100 total):
gridTiles = []
for r in range(totalSpaces):
for c in range(totalSpaces):
tiles = Rectangle(Point(borderSet + r * spaceSize, borderSet + c * spaceSize), Point(borderSet + (r + 1) * spaceSize, borderSet + (c + 1) * spaceSize))
tiles.setWidth(2)
tiles.draw(board)
gridTiles.append(tiles)
I know that the Rectangle does not support indexing (as shown in the TypeError I get), but I need to be able to access one specific rectangle later in my code.
Is there a way to somehow index each rectangle, so I can do something along the lines of gridTiles[3][7] later (although, of course, the way it is now, it will not allow that)? And, incidentally, I currently do not know the things that are like __something__, so I can’t easily use any method that’s done like that.
Make
gridTileshave nested lists:Now you should be able to index like you want: