# Pygame making Snake, need help with generating fruit with a random color

This is my function for generating an apple, I want it to generate a random color each time the snake eats it.

    def AppleGenerator():
fruit_colors = [crimson,powderblue,yellow,hotpink,orange,darkorchid,lime]
x = random.randrange(1,6)
return fruit_colors[x]


This is when I call it, AppleX, AppleY, and size are just the dimensions of the rectangle. The problem is that the 'apple' just flashes random different colors from the list and doesn't stick to one color.

 pygame.draw.rect(gameScreen,AppleGenerator(),[AppleX,AppleY,size,size])


By the way, the reason why I didn't just simply do

def AppleGenerator():
fruit_colors = [crimson,powderblue,yellow,hotpink,orange,darkorchid,lime]
return random.randrange(fruit_colors[0],fruit_colors[6])


is because the colors are tuples, and randrange() only accepts integers.

You're calling the AppleGenerator() function every time you draw the fruit, so each time you draw it, that function gives it a new random colour.
// Get colour (call this once per apple)