TypeError: must be pygame.Surface, not list

TypeError: must be pygame.Surface, not list

这是我的代码,我试图制作一个矩形:

import pygame
import sys
pygame.init()
color = [255,20,78]
black = [0,0,0]
screen = pygame.display.set_mode((800,600), 0, 32)
pygame.display.set_caption("Rectangle")

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    screen.fill(color)
    pygame.draw.rect(color, black, [400,300,10,10])
    pygame.display.update()

我不明白这个错误对 Surface 意味着什么 有人可以帮帮我吗? 任何帮助表示赞赏! 哦,请不要对我发誓,我仍然是一个程序菜鸟。 错误:

Traceback (most recent call last):
  File "C:\Users\Hugo\Desktop\Pygame\game - kopie.py", line 15, in <module>
    pygame.draw.rect(color, black, [400,300,10,10])
TypeError: must be pygame.Surface, not list

问题在行

pygame.draw.rect(color

其中颜色是列表。

draw.rect 需要 Surface 作为第一个参数。

pygame.draw.rect() draw a rectangle shape rect(Surface, color, Rect, width=0) -> Rect Draws a rectangular shape on the Surface. The given Rect is the area of the rectangle. The width argument is the thickness to draw the outer edge. If width is zero then the rectangle will be filled.

Keep in mind the Surface.fill() method works just as well for drawing filled rectangles. In fact the Surface.fill() can be hardware accelerated on some platforms with both software and hardware display modes.

请传递 Surface 作为第一个参数。