I'm new to programming, python and pygame. This is some code I wrote to draw random colored rectangles on an 800 x 600 canvas. It does what I expected it to do but becomes unresponsive if I click anywhere on the window. I am on a 64 bit windows 7 system running 32 bit python 2.7 with the appropriate pygame 1.9.1.
import pygame as pg from random import randint as rand pg.init() screen_size = (800,600) canvas = pg.display.set_mode(screen_size) pg.display.set_caption('Random Rects') curEvent = pg.event.poll() running = True todraw =  class rect: def __init__(self, x, y, (width, height)): self.x = x self.y = y self.width = width self.height = height self.color = (rand(0,255),rand(0,255),rand(0,255)) def topygame(self): return self.color,(self.x,self.y,self.x+self.width,self.y+self.height) for x in range(100): todraw.append(rect(rand(0,800), rand(0,600), (rand(0,100), rand(0,100)))) for x in todraw: pg.draw.rect(canvas, *(x.topygame())) while running: pg.display.flip() for event in pg.event.get(): if event.type==pg.event.QUIT: running = False