pygame.error: Couldn't open images\ship.bmp的解决办法
来源:互联网 发布:南京网络问政 编辑:程序博客网 时间:2024/06/04 23:31
在《python编程:从入门到实践》这本书中的《外星人入侵》的项目里有如下代码:
import pygameclass Ship(): def __init__(self,screen): """初始化飞船并设置其初始位置""" self.screen = screen # 加载飞船图像并获取其外接矩形 self.image = pygame.image.load('images/ship.bmp') self.rect = self.image.get_rect() self.screen_rect = screen.get_rect() # 将每艘新飞船放在屏幕底部中央 self.rect.centerx = self.screen_rect.centerx self.rect.bottom = self.screen_rect.bottom def blitme(self): """在指定位置绘制飞船""" self.screen.blit(self.image,self.rect) # 根据指定位置将图像绘制到屏幕上
在运行时可能会出现如下报错:
File “d:\python3wp\alien_invasion\ship.py”, line 8, in init
self.image = pygame.image.load(‘images/ship.bmp’)
pygame.error: Couldn’t open images/ship.bmp
经本人试用成功的解决办法如下:
将self.image = pygame.image.load(‘images/ship.bmp’)中的图片路径补全。(因为是Windows系统所以用反斜杠“\”)
然后在路径前加一个 r 读取图片文件。具体代码如下:
self.image = pygame.image.load(r'D:\python3wp\alien_invasion\images\ship.bmp')
阅读全文
1 0
- pygame.error: Couldn't open images\ship.bmp的解决办法
- jupyter notebook下提示Couldn't open CUDA library libcudnn.so的解决办法
- Couldn't resolve error 的问题
- The operation couldn't be completed (LaunchServicesError error 0.)解决办法
- ERROR: Couldn't open giveio.sys Failed to open Dongle JTAG(parallel port)
- sftp error: Couldn't canonicalize
- 安装vc6出现couldn't find acme setup的解决办法
- Couldn't reserve space for cygwin's heap 的解决办法
- 关于出现错误:_tkinter.TclError: couldn't open "E:\Python系列\Python程序\Python安装.gif"tkinter中不能打开GIF格式图片的解决办法
- couldn’t open CUDA library cupti64_80.dll
- rman: can't open target的解决办法
- linux下soap 出现 SOAP-ERROR: Parsing WSDL: Couldn't load from 解决办法
- Couldn't reserve space for cygwin's heap, Win32 error 487 解决办法
- Couldn't resolve error at 'ntdll!NtOpenProcess'
- couldn’t be completed. (LaunchServicesError error 0.)
- couldn’t be completed. (LaunchServicesError error 0.)
- TensorFlow1.2的一个bug(Couldn't open CUDA library libcupti.so.8.0.)
- evc4.0 MFC开发中,fatal error 1015 can't open file include aygshell.h 的解决办法
- 移植u-boot-2012.04----支持NORFlash启动
- WPF中Brush的派生类,实例发光的小球
- mybatis中动态sql常用的标签
- MySql数据库面试
- graphviz Windows中文乱码
- pygame.error: Couldn't open images\ship.bmp的解决办法
- 甲骨學鼎鼑熯文組系:鬼田
- Kotlin中问号(?)和两个叹号(!!)
- epoll讲解
- springmvc+Mybatis 分页查询的简单实现
- java 调用shell时出现假死问题
- 排列组合问题
- 汇编伪指令收藏
- 变量处理