类型错误:必须是pygame.Surface,就不一一列举

问题描述:

这是我的代码,我试图让一个矩形:类型错误:必须是pygame.Surface,就不一一列举

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() 

我不明白是什么错误与表面 有人可以帮我指? 任何帮助表示赞赏! 哦,请不要向我发誓,我仍然是一个程序noob。 错误:

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作为第一个参数。