""" clicks.py Here is a program that creates a grid of rectangles. (1) Put the rectangle creation into a MyRect class, so that the loop in make_rects becomes just for row in range(grid_size): for column in range(grid_size): rects.append(MyRect(row, column, window)) Hint: you'll need to create a store a Rectangle object within the MyRect. (2) Create a MyClickable class, a variation of the MyRect class which has a .check_click(point) method, which (a) checks to see if point is within the boundary of the rectangle, and (b) If it is, changes the color of the rectangle. Then at the end of the main() function, change it to while True: click_point = window.getMouse() for rect in rects: rect.check_click(click_point) ... and see what happens """ from graphics import * def display_message(message, window): """ Display the given message in the window. """ text = Text(Point(4, -.5), message) text.setSize(24) text.setFace('arial') text.setStyle('bold') text.draw(window) def make_window(pixel_size, grid_size): """ Return a new graphics window """ window = GraphWin("clicks", pixel_size, pixel_size) window.setCoords(-1, -1, grid_size + 1, grid_size + 1) return window def make_rects(grid_size, window): """ Return a list of Rectangles """ rects = [] for row in range(grid_size): for column in range(grid_size): rect = Rectangle(Point(row,column), Point(row+1, column+1)) rect.setFill('red') rect.setWidth(2) rect.draw(window) rects.append(rect) return rects def main(): (pixels, grid) = (600, 10) window = make_window(pixels, grid) rects = make_rects(grid, window) display_message("Click somewhere to quit.", window) click = window.getMouse() if __name__ == '__main__': main()