Pygame issuse on mac os x 10.7.3

2019-06-03 12:41发布

So, I am starting with python in a mac Lion, and I am trying to make my first program with an image: here is the code of the program

import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 30
fpsClock = pygame.time.Clock()

DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32)
pygame.display.set_caption('Animation');

WHITE = (255, 255, 255)
catImg = pygame.image.load("cat.png")
catx = 10
caty = 10
direction = 'right'

while True:
    DISPLAYSURF.fill(WHITE)

    if direction == 'right':
        catx += 5
        if catx == 280:
            direction = 'down'
    elif direction == 'down':
        caty += 5
        if caty == 220:
            direction = 'left'
    elif direction == 'left':
        catx -= 5
        if catx == 10:
            direction = 'up'
    elif direction == 'up':
        caty -= 5
        if caty == 10:
            direction = 'right'

    DISPLAYSURF.blit(catImg, (catx, caty))

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

    pygame.display.update()
    fpsClock.tick(FPS)

When the program runs, there is a mistake:

Traceback (most recent call last):
  File "catanimation.py", line 13, in <module>
    catImg = pygame.image.load("cat.png")
pygame.error: File is not a Windows BMP file

What could be the cause of this problem

INFO: Instead of an image I used a surface and It worked good. I suspect the problem might be related to my pygame installation but I'm not sure

1条回答
Lonely孤独者°
2楼-- · 2019-06-03 13:16

Your code actually worked "out of the box" for me on Python 2.6 (Mac OS X 10.6).

If you're using the Python version supplied with your OS (Apple 2.7) make sure you're using this package: Pygame for Apple supplied Python - Mac OS X 10.7 .

查看更多
登录 后发表回答