在pygame窗口中输出事件队列中的所有事件。
import random
import pygame
import sys
SIZE = WIDTH, HEIGHT = 640, 396
FPS = 60
pygame.init()
screen = pygame.display.set_mode(SIZE, 0, 32)
pygame.display.set_caption("Event")
clock = pygame.time.Clock()
font = pygame.font.SysFont(None, 25)
font_height = font.get_linesize()
event_list = []
line_num = SIZE[1]
running = True
while running:
event = pygame.event.wait()
event_list.append(str(event))
event_text = event_list[-line_num:]
if event.type == pygame.QUIT:
sys.exit()
screen.fill((54, 59, 64))
y = SIZE[1] - font_height
for text in reversed(event_list):
rgb = tuple((random.randint(0,255) for i in range(3)))
screen.blit(font.render(text, True, rgb), (0, y))
y -= font_height
pygame.display.update()