import pygame as py
import sys
py.init()
w, h = 600, 400
x,y=0,0
hat = ['']
font = py.font.Font('font/Font.ttf.ttf',30)
windows = py.display.set_mode((w, h ))
py.display.set_caption('game')
run = True
i = 0
while run:
text = font.render(hat[i], 1, 'white')
windows.blit(text, (x, y))
for event in py.event.get():
if event.type == py.QUIT:
run = False
py.quit()
sys.exit()
if event.type == py.KEYDOWN:
print(event.unicode)
if event.key == py.K_RETURN:
i += 1
x = 0
y += 30
hat.append('')
print(hat)
print(i)
elif event.key == py.K_BACKSPACE:
new_hat = hat[i][:-1]
windows.fill('black')
if i>0:
for a in range(i):
text = font.render(hat[a], 1, 'white')
windows.blit(text, (0, a*30))
print(new_hat)
hat[i] = new_hat
else:
hat[i] = hat[i] + event.unicode
py.display.update()
运行之后