无法找出代码的错误(从newboston)

2024-04-20 00:10:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在遵循newbostonsGame developement Tutorials,在运行代码时遇到了一个错误:

bif = "bg.jpg"
mif = "ball.png"

import pygame, sys
from pygame.locals import *

pygame.init()

screen = pygame.display.set_mode((400,300),0,32)

background = pygame.image.load(bif).convert()
mouse_c = pygame.image.load(mif).convert_alpha()

while True:
    for event in pygame.event.get():
        if evenet.type == QUIT:
            pygame.quit()
            sys.exit()
    screen.blit(background, (0,0))

    x,y = pygame.mouse.get_pos()
    x -= mouse_c.get_width() / 2
    y -= mouse_c.get_height()/2

    screen.blit(mouse_c,(x,y))

    pygame.display.update()

我得到了错误:

Traceback (most recent call last):
  File "bucky.py", line 11, in <module>
    background = pygame.image.load(bif).convert()
pygame.error: Couldn't open bg.jpg

我保存了一个来自google图片的图片,并给它命名背景.jpg,所以我不知道是什么导致了这个问题。如果有人能帮我,那就太好了。谢谢


Tags: imageimportconvertget错误sysloadscreen