PYGAME: how to activate an event by pressing the key

Thus, I am having trouble activating the sound when I press a key.

what i still

if event.type == pygame.key(K_a):
    self.sound.play()

I get an error code called global name "K_a" that is not defined.

If anyone can help me fix this code? Thanks!

+4
source share
1 answer

pygame.K_a. : if event.type == pygame.key(pygame.K_a):.   , , , pygame . pygame : from pygame import *. pygame.key, . : if event.type == pygame.K_a:

+3

All Articles