小编Dim*_*uid的帖子

TypeError:参数 1 必须是 pygame.Surface,而不是 str 我该如何修复?

我从 youtbe 视频中编码了这个,他似乎做得很好,但当我尝试时,我在底部收到错误消息,我很困惑,我需要帮助。

#!/usr/bin/env python

import pygame, sys

from pygame.locals import *

pygame.init()

screen = pygame.display.set_mode((370, 572), 0, 32)

backgroundfile = "back.png"
mousefile = "mouse.png"

back = pygame.image.load(backgroundfile).convert()
mouse = pygame.image.load(mousefile).convert_alpha()

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    #Now we have initialized everything lets start with the main part

    screen.blit("back.png", (0,0))

    pygame.display.flip()
Run Code Online (Sandbox Code Playgroud)

当我运行该程序时,我收到错误:

Traceback (most recent call last):
  File "Tutorial 5 First game.py", line 26, in <module>
  screen.blit("back.png", (0,0))
TypeError: argument 1 must be pygame.Surface, …
Run Code Online (Sandbox Code Playgroud)

python linux pygame raspberry-pi

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

linux ×1

pygame ×1

python ×1

raspberry-pi ×1