Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用PyCharm时Pygame中的图像错误_Python_Pygame_Pycharm - Fatal编程技术网

Python 使用PyCharm时Pygame中的图像错误

Python 使用PyCharm时Pygame中的图像错误,python,pygame,pycharm,Python,Pygame,Pycharm,我正在学习Python和Pygame,并一直在为Mac使用PyCharm。我试图将png图像加载到Pygame窗口,但出现错误:Pygame.error:文件不是Windows BMP文件。我用IDLE试过,效果很好。我能做些什么使它在PyCharm中工作?。我正在使用Python 2.7.5 这是我的密码: import pygame, sys pygame.init() screen = pygame.display.set_mode([640, 480]) screen.fill([255

我正在学习Python和Pygame,并一直在为Mac使用PyCharm。我试图将png图像加载到Pygame窗口,但出现错误:Pygame.error:文件不是Windows BMP文件。我用IDLE试过,效果很好。我能做些什么使它在PyCharm中工作?。我正在使用Python 2.7.5

这是我的密码:

import pygame, sys
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])
my_ball = pygame.image.load('beach_ball.png')
screen.blit(my_ball, [50, 50])
pygame.display.flip()
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()

请尝试google:pygame.error:文件不是Windows BMP文件

以下是我在谷歌上找到的第一个答案:

初学者快速解决方案:

安装Python 2.7.5

进入应用程序->Python 2.7->更新Shell配置文件

Python 2.7.5现在应该是您的默认Python。在终端中运行应用程序,一切正常

这是迄今为止解决这个问题最简单的方法。希望这有帮助。

找到了解决方案:安装了这个Pygame版本,一切正常: