Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to change color of square in pygame with keypress

while True:
    for events in pygame.event.get():
        if events.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        #Here for any commands inside the for loop  
        if (events.type == pygame.KEYDOWN) and (events.key == pygame.K_SPACE):
            COLOR = (random.randint(ZEROINTENSITY, MAXINTENSITY), random.randint(ZEROINTENSITY, MAXINTENSITY), random.randint(ZEROINTENSITY, MAXINTENSITY))
            #note- we have skipped the last parameter and by default, 0 is taken
     pygame.draw.circle(SCREEN, COLOR, POS, RADIUS)
     pygame.display.update()
Source by diycomputerscienceandelectronics.wordpress.com #
 
PREVIOUS NEXT
Tagged: #change #color #square #pygame #keypress
ADD COMMENT
Topic
Name
8+5 =