fifiman
fifiman

Reputation: 264

Pygame not working

while done == False:
    for event in py.event.get():
        if event.type == py.QUIT:
            done = True
        elif event.type == KEYDOWN:
            if event.key == K_UP:
                player_y += 1

this is my code and my debugger keeps saying that KEYDOWN is not defined. Help please

Upvotes: 1

Views: 209

Answers (3)

Ryan's World
Ryan's World

Reputation: 64

Include this in your code or it wont work

while done == False:
    for event in py.event.get():
        if event.type == py.QUIT:
            done = True
        if event.type == py.KEYDOWN:
            if event.key == py.K_UP:
                player_y += 1

Upvotes: -1

iKlsR
iKlsR

Reputation: 2672

the full call is pygame.KEYDOWN etc

instead of manually typing out the ones that you need just add this below your import pygame line from pygame.locals import * this should work for all the keys you need.

Upvotes: 2

Raptor
Raptor

Reputation: 54212

include this on the top of your code:

from pygame import KEYDOWN, K_UP

Add more keys such as K_LEFT, K_RIGHT, K_UP, K_DOWN, K_e if you like

Upvotes: 4

Related Questions