''' Display the window with BLACK color initally. When KKEYDOWN, change color to RED. When KEYUP, change color to GREEN When MOUSEBOTTONDOWN, change color BLUE by Ching-Shoei Chiang ''' import pygame, sys from pygame.locals import * # (R,G,B) BLACK = (0,0,0) # Three 0 RED = (255,0,0) # Two 0 GREEN = (0,255,0) BLUE = (0,0,255) CYAN = (0,255,255) # One 0 MAGENTA = (255,0,255) YELLOW = (255,255,0) WHITE = (255, 255, 255) # Three 255 pygame.init() wcolor = BLACK screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Professor Chiang's Game") # Setting the main program loop while True: # Main event loop for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: wcolor = RED elif event.type == pygame.KEYUP: wcolor = GREEN elif event.type == pygame.MOUSEBUTTONDOWN: wcolor = BLUE screen.fill(wcolor) pygame.display.flip() if __name__ == '__main__': main()