首先安装pygame模块:
pip install pygame
然后看第一个小例子,展示游戏屏幕,代码保存为game1.py:
import pygame,sys
'''
遇到python不懂的问题,可以加Python学习交流群:1004391443一起学习交流,群文件还有零基础入门的学习资料
'''
pygame.init()
screen = pygame.display.set_mode((600,400))
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("apple.png")
ballrect = ball.get_rect()
screen.fill((255,255,255))
screen.blit(ball,ballrect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.display.update()
允许:python game1.py