global name 'K_ENTER' is not defined

0

That error comes to me when I try to press the enter or even when I want to press the space I get the same error ...

def Menu():
   #Llama a la variable global dificultad
   global dificultad
   #Carga y guarda la imagen de la carpeta dibujo
   Nombre_Full = os.path.join('dibujo', 'Fondo_Menu4.png')
   #Carga la imagen y la asigna a la variable Menug
   Menug=pygame.image.load(Nombre_Full)
   #Muestra en pantalla la imagen guardada en Ganag
   screen.blit(Menug,(0,0))
   #Ciclo infinito que terminara cuando el usuario aprete un boton
   while dificultad == 0:
       for event in pygame.event.get():
          if event.type == pygame.KEYDOWN:
             if event.key==K_SPACE:
                 dificultad =1
             if event.key==K_ENTER: 
                 dificultad = 2
       pygame.display.flip()
       pygame.time.delay(50)                  
    
asked by Wolf 10.10.2018 в 09:32
source

1 answer

0

I've never used Python, but a 2 minute search takes me to the pygame documentation, with a list of the identifiers used to distinguish the letters on the keyboard: link

Looking at the list, it is clear that there is no identifier K_ENTER (which is what the error message says) but an identifier K_RETURN .

Also, since you do not put pygame. in front, look for the symbol as a local symbol, and not as a symbol of pygame .

Solution:

if event.key == pygame.K_SPACE:
   dificultad =1
if event.key== pygame.K_RETURN: 
   dificultad = 2
    
answered by 10.10.2018 в 09:41