I am attempting to write a program in Python 3.6, with the help of pygame (A Python module) which is supposed to flash Red, Green, and Blue quickly on the screen. The program runs as intended for approximately ten to fifteen seconds before it stops responding. (I have noticed that only 3 events are printed to the console, when there should be A LOT more.)
import pygame
import threading
import time
'''
IMPORTS ARE ABOVE THIS LINE
'''
class EventHandler(threading.Thread):
def run(self):
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()
'''
CLASSES ARE ABOVE THIS LINE
'''
# Initializer
gameInit = pygame.init()
# Colors
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
# Setup Crap
gameDisplay = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Pygame Colors")
# Event Handler
handler = EventHandler()
handler.start()
# Game Loop
while True:
gameDisplay.fill(red)
pygame.display.update()
time.sleep(0.1)
gameDisplay.fill(green)
pygame.display.update()
time.sleep(0.1)
gameDisplay.fill(blue)
pygame.display.update()
time.sleep(0.1)