1.pygame的定义
Pygame是跨平台Pyth,Pygame 作者是 Pete Shinners, 协议为 GNU Lesser General Public License。
pygame包含图像、声音。
建立在SDL基础上,允许实时电子游戏研发而无需被低级语言(如机器语言和汇编语言)束缚。基于这样一个设想,所有需要的游戏功能和理念都(主要是图像方面)都完全简化为游戏逻辑本身,所有的资源结构都可以由高级语言提供,如Python。
Pygame 原为代替突然停止的 pySDL
2.pygame的安装
pip install pygame
如果发现外国的代码下载太慢,还可以使用豆瓣提供的景象服务
pip install pygame -i https://pypi.douban.com
当出现类似于下面的代码时,证明安装成功
pip install pygame
Requirement already satisfied: pygame in c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages (1.9.6)
我们安装好了pygame后,肯定要向pygame问好,那我们就建立一个名叫HelloWorld的程序
3.使用pygame
#第一步:引入pygame和sys库
import pygame
import sys
#第二步:初始化配置
pygame.init()
width = 800
height = 600
size = width , height
screen = pygame.display.set_mode(size)
#第三步:获取事件
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#第三步:更新屏幕
pygame.display.update()
我们可以发现,出现了一个pygame窗口
我们对于pygame的配置就完成了