Когда я проигрываю основной файл, он сообщает self.image.fill(«белый») Ошибка типа: неверный аргумент цвета в этом файле, как я могу это исправить?

#python #pygame

Вопрос:

«‘python»‘
импорт 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)
 

Ответ №1:

Скорее всего, вы используете более старую версию 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
 

И в 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)>
 

Вы можете обновить свою версию с pip install pygame --update помощью или , возможно, с pip3 помощью, в зависимости от вашей системы.