When I play the main file it told self.image.fill(‘white’) TypeError: invalid color argument in this file, how can I fix it?

”’python”’
import pygame

class Laser(pygame.sprite.Sprite):
    def __init__(self,pos):
        super().__init__()
        self.image = pygame.Surface((4,20))
        self.image.fill('white')
        self.rect = self.image.get_rect(center = pos)

Answer

You are likely using an older version of pygame

>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> pygame.Surface((20,20)).fill("white")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: invalid color argument

And in 2.0.0+

>>> import pygame
pygame 2.0.1 (SDL 2.0.14, Python 3.8.6)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> pygame.Surface((20,20)).fill("white")
<rect(0, 0, 20, 20)>

You can update your version with pip install pygame --update or perhaps with pip3, depending on your system.