Faking Multiple Buttons in graphics.py

A couple students had asked me whether this graphics library module is capable of creating buttons by detecting if the region you clicked in falls with a drawn shape.

The answer is yes!

The solution isn't simple, and includes content the majority of the class has not yet learned; however it works.

The program below consists of two functions:

  1. point_in_shape(p, buttons_list): This takes as parameters to this function two objects: a Point object, likely one created as a return value from .getMouse called on a GraphWin instance object, and a list of "buttons", or really just a list of shape objects that you wish to consider as buttons. It then checks to see if the point p lies within any of these shapes.

  2. main() Simply creates a series of random shapes (really, just three rectances, and a circle). Clicking on a button with cause it to flash black.