import pygame
import sys
pygame.init()
size = width,height = 600,400
screen = pygame.display.set_mode(size)
pygame.display.set_caption("tang demo")
bg = (0,0,0)
screen.fill(bg)
#设置字体格式及大小
font = pygame.font.Font(None,20)
#获取行高
line_height = font.get_linesize()
#初始化positon
position = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#绚染,消除锯齿,设置字体颜色,位置是从左到右)
screen.blit(font.render(str(event),True,(0,255,0)),(0,position))
#下一行
position += line_height
#位置大于行高的时候
if position > height:
#清屏,成黑色
position = 0
screen.fill(bg)
#刷新屏幕
pygame.display.flip()
效果图: