【问题标题】:Pygame keyboard input doesn't works - PythonPygame键盘输入不起作用 - Python
【发布时间】:2020-08-16 12:20:14
【问题描述】:

有人可以帮助我吗?当我在键盘上按 -A - 时,什么也没有发生

import pygame
pygame.init()

pygame.display.set_caption("PyGame")
pygame.display.set_mode((640,480))


while (True): 
    for event in pygame.event.get():
        if (event.type == pygame.K_a):
            pygame.quit()

【问题讨论】:

    标签: python input pygame keyboard key


    【解决方案1】:

    应该可以的:

    #!/usr/bin/env python3
    
    import pygame
    import sys
    
    
    pygame.display.set_caption("PyGame")
    pygame.display.set_mode((640, 480))
    pygame.init()
    
    while (True):
        for event in pygame.event.get():
             if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_a):
                    pygame.quit()
                    sys.exit(0)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    相关资源
    最近更新 更多