I seem to be having problems with K_SPACE I tried making searching for the event a def just to trouble shoot but it only worked for QUIT. Can anyone tell me why I am not see a print when I hit the space bar
import pygame, sys from pygame.locals import *
pygame.init() DISPLAYSURF = pygame.display.set_mode((400,300)) pygame.display.set_caption('Hello World!')
WHITE = (255, 255, 255) GREEN = (0, 255, 0) BLUE = (0, 0, 128)
fontObj = pygame.font.Font('freesansbold.ttf', 32) textSurfaceObj = fontObj.render ('Hello World!', True, GREEN, BLUE) textRectObj = textSurfaceObj.get_rect() textRectObj.center = (200, 150)
def main(): while True: # main game loop DISPLAYSURF.fill(WHITE) # draw the window DISPLAYSURF.blit(textSurfaceObj,textRectObj) checkForQuit() checkForSpaceBar() pygame.display.update()
def checkForQuit(): for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit()
def checkForSpaceBar(): for event in pygame.event.get(): if event.type == K_SPACE and KEYDOWN: print event.key
if name == 'main': main()