官網
安裝
pip install pygame
如下圖所示,說明安裝成功了:
最小框架
感覺註釋已經很清楚了:
# 導入相關模塊
import sys, pygame
'''
pygame 初始化
pygame.init 初始化所有模塊,也可以初始化具體的模塊,如:
pygame.font.init()
'''
pygame.init()
# 窗口大小
size = width, height = 320, 240
# 顏色黑
black = 0, 0, 0
# 設置窗口大小
screen = pygame.display.set_mode(size)
# 設置窗口標題
pygame.display.set_caption("我的 PyGame 窗口")
# 加載一張圖片
ball = pygame.image.load("res/intro_ball.gif")
ballrect = ball.get_rect()
# 主循環
while True:
# 事件處理
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
# 繪製更新圖形
screen.fill(black)
screen.blit(ball, ballrect)
pygame.di![在這裏插入圖片描述](https://img-blog.csdnimg.cn/20191111163832357.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9zdW5zaS5ibG9nLmNzZG4ubmV0,size_16,color_FFFFFF,t_70)splay.flip()
效果如下: