- Python
高级python编程-pygame 第一课
- 2024-3-9 19:16:02 @
第一个Python程序:
import sys
import pygame
from pygame.locals import *
pygame.init() # 初始化pygame模块
WIDTH = 800 # 定义游戏窗口的宽
HEIGHT = 480 # 定义游戏窗口的高
SCREEN_SIZE = (WIDTH, HEIGHT) # 定义一个元组
screen = pygame.display.set_mode(SCREEN_SIZE) # 初始化一个显示画面的窗口
pygame.display.set_caption("MyPygame") # 设置标题
while True: # 游戏主循环
for event in pygame.event.get(): # 获取事件
if event.type == QUIT: # 退出
pygame.quit() # 退出pygame模块
sys.exit() # 退出系统
pygame.display.update() # 更新窗口画面显示
填充背景颜色
import sys
import pygame
from pygame.locals import *
pygame.init() # 初始化pygame模块
WIDTH = 800 # 定义游戏窗口的宽
HEIGHT = 480 # 定义游戏窗口的高
SCREEN_SIZE = (WIDTH, HEIGHT) # 定义一个元组
screen = pygame.display.set_mode(SCREEN_SIZE) # 初始化一个显示画面的窗口
pygame.display.set_caption("MyPygame") # 设置标题
blue = (0, 162, 232) # 蓝色
while True: # 游戏主循环
for event in pygame.event.get(): # 获取事件
if event.type == QUIT: # 退出
pygame.quit() # 退出pygame模块
sys.exit() # 退出系统
screen.fill(blue) # 用纯色填充窗口
pygame.display.update() # 更新窗口画面显示
0 条评论
目前还没有评论...