1

Can someone help me ? When i press - A - on the keyboard , nothing happen

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()

1 Answer 1

2

That should work:

#!/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)
Sign up to request clarification or add additional context in comments.

1 Comment

If you like this answer please mark it as solved to let other users know your problem is solved. Also see What should I do when someone answers my question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.