I am trying to make a grid, and when any object on the grid is clicked on, it changes to a certain color based on whatever I need it to
When I do that, I get a ValueError, saying that my color argument is invalid
However, I'm using constants for my colors, and the constants are set to tuples, which seems to be the right type.
I have looked online, but everyone's problems were that they were not passing in a tuple, but I am pretty sure I am
Here are my constants, then all the code
WIDTH = 800
WIN = pygame.display.set_mode((WIDTH, WIDTH))
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
PURPLE = (128, 0, 128)
ORANGE = (255, 265, 0)
GREY = (128, 128, 128)
TURQUOISE = (64, 224, 208)
main(WIN, WIDTH)
def main(win, width):
while run:
draw(win, grid, ROWS, width)
def draw(win, grid, rows, width):
for row in grid:
for node in row:
node.draw(win)
class Node:
def __init__(self, row, col, width): #there are other arguments, but not needed
self.row = row
self.col = col
self.x = row * width
self.y = col * width
self.width = width
self.color = WHITE
def draw(self, win):
pygame.draw.rect(win, (self.color), (self.x, self.y, self.width, self.width))
#There are functions that change the nodes color like these
def make_closed(self):
self.color = RED
Traceback (most recent call last):
File "--", line 154, in <module>
main(WIN, WIDTH)
File "--", line 118, in main
draw(win, grid, ROWS, width)
File "--", line 93, in draw
node.draw(win)
File "--", line 58, in draw
pygame.draw.rect(win, (self.color), (self.x, self.y, self.width, self.width))
ValueError: invalid color argument
I'm new to Stack Overflow, so any input on how to better ask questions would be greatly appreciated, and let me know if you need anything else! (My on-click function is a bit more complicated than needed for testing, but I can also put that code in there) There are file names, I removed them. Thanks for your help in advance!