pygame游戏之旅 创建游戏窗口界面
时间:2021-03-22 09:08:48|栏目:Python代码|点击: 次
pygame创建游戏窗口界面,供大家参考,具体内容如下
使用pygame前一定要先导入pygame而且肯定要先初始化pygame
import pygame pygame.init()
创建一个800 x 600的窗口,函数返回一个显示界面
gameDisplay = pygame.display.set_mode( (800,600) )
修改窗口的标题,无需返回
pygame.display.set_caption('A bit Racey')
pygame.time模块给我们提供了一个Clock的对象,我们需要创建并接收这个对象
clock = pygame.time.Clock()
我们需要创建打断程序的部分
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
print(event)
pygame.display.update()
clock.tick(60)
最后推出pygame和python
pygame.quit() quit()
代码是:
import pygame
pygame.init()
gameDisplay = pygame.display.set_mode( (800,600) )
pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock()
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
print(event)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
得到的结果是:

鼠标移动时打印的操作:

上一篇:Python Multiprocessing多进程 使用tqdm显示进度条的实现
栏 目:Python代码
下一篇:python定时关机小脚本
本文标题:pygame游戏之旅 创建游戏窗口界面
本文地址:http://www.codeinn.net/misctech/85646.html






