【问题标题】:TypeError: must be pygame.Surface, not listTypeError:必须是 pygame.Surface,而不是列表
【发布时间】:2015-04-24 11:40:33
【问题描述】:

这是我的代码,我正在尝试制作一个矩形:

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

【问题讨论】:

    标签: python pygame surface


    【解决方案1】:

    问题出在一行

    pygame.draw.rect(color

    颜色是列表。

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

    pygame.draw.rect() 绘制一个矩形形状rect(Surface, color, Rect, width=0) -> Rect 在 Surface 上绘制一个矩形。给定的 Rect 是矩形的面积。宽度参数是厚度 绘制外边缘。如果宽度为零,则矩形将为 填满。

    请记住,Surface.fill() 方法同样适用于绘图 填充矩形。实际上 Surface.fill() 可以是硬件 在一些同时具有软件和硬件显示的平台上加速 模式。

    请将Surface 作为第一个参数。

    【讨论】:

      猜你喜欢
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      相关资源
      最近更新 更多