python运行完不能显示图_Python Pygame无法正确显示图像
我是Python的新手,我从Eric Matthes的“ Python崩溃课程”开始学习.我正处于Pygame一章的开头,并且遵循代码,但是我加载的图像总是看起来损坏,我也不知道为什么.代码来自本书.第一个文件:
import pygame
class Ship():
def __init__(self, screen):
"""Initialize the ship and set its starting position."""
# Load the ship image and get its rect.
self.image = pygame.image.load('ship.bmp')
self.screen = screen
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
# Start each new ship at the bottom center of the screen.
self.rect.centerx = self.screen_rect.centerx
self.rect.bottom = self.screen_rect.bottom
def blitme(self):
self.screen.blit(self.image, self.rect)
第二档:
import sys
import pygame
from settings import Settings
from ship import Ship
def run_game():
# Initialize game and create a screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
ship = Ship(screen)
bg_color = (230, 230, 230)
# Start the main loop for the game.
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Make the most recently drawn screen visible.
screen.fill(ai_settings.bg_color)
ship.blitme()
pygame.display.flip()
run_game()
设置文件:
class Settings():
"""A class to store all settings for Alien Invasion."""
def __init__(self):
"""Initialize the game's settings."""
# Screen settings
self.screen_width = 800
self.screen_height = 600
self.bg_color = (230, 230, 230)
我的bmp看起来像这样:
我尝试添加其他图像,但没有运气:
我该如何解决?
python运行完不能显示图_Python Pygame无法正确显示图像相关推荐
- python运行完不能显示图_【已解决】Python中通过Image的open之后,去show结果打不开bmp图片,无法正常显示图片...
[问题] 在windows的cmd命令行下,使用Python的PIL库打开并显示一个jpg图片:openedImg = Image.open(saveToFile); print "open ...
- python编写一个弹球游戏_python pygame实现挡板弹球游戏
学了一天pygame,用python和pygame写一个简单的挡板弹球游戏 GitHub: # -*- coding:utf-8 -*- from sys import exit import pyg ...
- python写完程序保存_Python学习笔记——文件处理
1.文件路径 1.1 不同系统环境下的路径 1.2 当前工作目录 1.3 绝对路径和相对路径 1.4 新建文件夹-- os.makedirs() 2.文件的读写 2.1 打开文件 2.2 读写文件 3 ...
- python运行不了指令_python不是内部命令或外部命令,也不是可执行程序解决方法...
简述 常见于新手初装python,然后忘记勾选设置环境变量(PATH),或者没有重启,然后运行教程中的python命令时出现. 有两个解决方法:1.设置环境变量,然后重启. 2.新建命令. 如果你打算 ...
- python运行脚本被杀死_Python脚本被杀死
环境 烧瓶0.10.1 SqlAlchemy 1.0.10版 Python 3.4.3 使用unittest 我已经创建了两个独立的测试,它们的目标是通过700k条记录查看数据库并进行一些字符串查找. ...
- python运行微软图标代码_Python读取xlsx数据生成图标代码实例
运行结果: 程序代码如下: #将excel中的数据进行读取分析 import openpyxl import numpy as np import math import matplotlib.pyp ...
- python编写2048游戏代码_python pygame实现2048游戏
实现2048相对来说比较简单,用4*4的二维数组保存地图,pygame.key.get_pressed()获取键盘操作,详见代码. 效果图 代码 # -*- coding: utf-8 -*- #!/ ...
- python运行界面英文翻译_python使用百度api翻译中英文
python使用百度api翻译中英文 写程序取变量名的时候,常常需要翻译单词,或者将中文翻译成英语.有道词典,必应词典都很好,可是...命令行习惯了还是觉得用在cmd里面调出程序使用起来也许会更爽.于 ...
- python运行出现数据错误_Python运行出错情况
1.错误内容:You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit byt ...
最新文章
- 当亿级流量App开始“玩”,到底在玩什么?
- 【struts2】第一个struts2实例
- Docker最全教程——MongoDB容器化(十三)
- element解决表格错位问题
- Flsak爱家租房--订单(获取用户订单、用户评论)
- html本地缓存未查看信息,不同用户看到了相同的信息-一次web系统缓存问题的解决...
- LFS-构建自己的linux
- 蓝桥杯基础练习字母图形
- flink安装以及运行自带wordcount示例(单机版,无hadoop环境)
- hibernate简单入门教程(四)---------关联映射
- php server 不支持,SQL server不支持utf8 php却用utf8的矛盾问题解决方法
- C#之Application.DoEvents()
- 记一个函数定义中,形参是空列表时要注意的问题
- 资源分配博弈之纳什均衡和斯塔克尔伯格模型
- win10未安装任何音频输出设备解决方案-记一次电脑的睿智问题
- java到达时间后自动执行代码_java设置按时间自动执行
- Directory traversal in Spring framework漏洞修复
- CentOS下配置apache虚拟主机
- eeprom--24LC64
- hybrid7 宝马active_宝马Active Hybrid 7:最快的混合动力轿车