1.安装pygame
install win:
pip install pygame
install mac:
pip install https://github.com/pygame/pygame/archive/master.zip
2.导入pygame库
import pygame
3.pygame的helloworld:
import pygame
from pygame.locals import *
import sys
# 使用pygame之前必须初始化
pygame.init()
# 设置用于显示的窗口,单位为像素
screen = pygame.display.set_mode((350, 500))
# 设置标题
pygame.display.set_caption("Hello,World!")
while True:
for event in pygame.event.get(): # 循环获取事件
if event.type == QUIT: # 若检测到事件类型为退出,则退出系统
pygame.quit()
sys.exit()
pygame.display.update() # 更新屏幕内容