Invalid Color Argument in PyGame

Viewed 34

I'm trying to fill the window with this background and I'm getting an 'invalid color argument' error. This confuses me because there isn't anything stating a color value (besides the picture, but I've changed that three times, so I don't believe that is the issue).

Code:

win.fill(pygame.image.load('Background/Yellow.png').convert()) 
if walkCount + 1 >= 27:
    walkCount = 0
    
if left:  
    win.blit(walkLeft[walkCount//3], (x,y))
    walkCount += 1                          
elif right:
    win.blit(walkRight[walkCount//3], (x,y))
    walkCount += 1
elif idle:
    win.blit(char1, (x, y))
    walkCount = 0
    
pygame.display.update() 
1 Answers

You cannot fill a window with a background image, however you can blit the background:

background = pygame.image.load('Background/Yellow.png').convert()
win.blit(background, (0, 0))

If the background is a different size than the window, you need to scale the background image with pygame.transform.smoothscale:

background = pygame.image.load('Background/Yellow.png').convert()
scaled_background = pygame.transform.smoothscale(background, win.get_size())
win.blit(scaled_background, (0, 0))
Related