我不知道为什么这不起作用,但它不捕获keydown。点击交叉工作正常,退出游戏。它可能是简单的东西,但我看不到它。 keydown在我的程序的其他部分工作正常,只是主菜单不起作用。下面是菜单部分的代码:Python PyGame KEYDOWN不工作
while menuOver == False:
Screen.fill(background_colour)
font1 = pygame.font.SysFont("Impact", 100)
font2 = pygame.font.SysFont("Impact", 50)
font3 = pygame.font.SysFont("Impact", 25)
lblTitle = font1.render("Python", 100, (black))
Screen.blit(lblTitle, (265, 50))
lblSubTitle = font2.render("Created With Python", 100, (black))
Screen.blit(lblSubTitle, (200, 200))
lblEasy = font3.render('Easy - Press 1', 100, (red))
Screen.blit(lblEasy, (100, 300))
lblNormal = font3.render('Normal - Press 2', 100, (red))
Screen.blit(lblNormal, (300, 300))
lblNightmare = font3.render('Nightmare - Press 3', 100, (red))
Screen.blit(lblNightmare, (525, 300))
lblLeaderboard = font3.render('Press L To View Leaderboard', 100, (black))
Screen.blit(lblLeaderboard, (90, 400))
lblInstructions = font3.render('Press I To View Instructions', 100, (black))
Screen.blit(lblInstructions, (425, 400))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_1:
menuOver = True
你必须检查'event.key == pygame.K_1',不'event.type == pygame.K_1' –
我不敢相信我错过了!感谢您指出它已经让我停留了很久! – BoJ