## ## example_grid.py ## ## by Kristina Striegnitz ## ## version 2/10/2010 ## ## Demonstrates how the functions in file grid_display can be used. ## import random from grid_display import run_display def make_grid(): # create a 3 by 3 grid representation grid = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] # display the grid cell_size = 40 run_display(grid, cell_size, on_click) def on_click(grid, row, col): """ This function specifies what should happen when there was a mouse click somewhere on the grid. The function gets called from the display, whenever a mouse click is registered. When it is called, the grid representation and two numbers indicating which row and column the mouse click was in are passed as parameter values. This function has to return the grid representation (potentially after modifying it). For the purposes of this example, we are not doing anything interesting when the grid gets clicked, we are just printing out which row and column the click was in. """ print row, col return grid make_grid()