I have no idea why the following is giving the error: name 'K_SPACE' is not defined. Importing pygame also imports the keyboard constants which includes 'K_SPACE'.
My code:
if pygame.key.get_pressed()[K_SPACE]: pygame.quit
Thanks
if you just did this:
import pygame
Then you need to do this:
if pygame.key.get_pressed()[pygame.K_SPACE]: pygame.quit
If the interpreter complains about the symbol not being defined, probably you need to fully qualify the name:
or explicitly import it:
from pygame import K_SPACE ... if pygame.key.get_pressed()[K_SPACE]: pygame.quit
Add:
from pygame.locals import *
to the beginning of your program, this will import the key variables.
Copyright © 2021 Jogjafile Inc.
if you just did this:
Then you need to do this: