#!/usr/bin/python

from random import *
from graphics import *
from _tkinter import *

def make_squares(win, num):
    squares = []
    for n in range(num):
        size = randrange(40,200)
        x = randrange(win.getWidth()-size)
        y = randrange(win.getHeight()-size)
        square = Rectangle(Point(x,y),Point(x+size,y+size))
        square.setFill("white")
        squares.append(square)
    return squares

def main():
    window = GraphWin("Minimalist Art?", 800, 800)
    window.setBackground("black")
    n = int(raw_input("How many squares would you like? "))
    
    squares = make_squares(window, n)
    for square in squares:
        square.draw(window)
    while True:
        try:
            square_num = int(raw_input("Which square would you like to color? "))
            color = raw_input("What color should it be? ")
            squares[square_num].setFill(color)
        except IndexError:
            print "That is not a valid square number."
        except TclError:
            print "That is not a valid color."
main()

