# Get a board size from the user. default_size = 30 str_prompt = "Specify a number of {0} for the board (default " \ + str(default_size) + "): " fcn_parse = lambda string: (True, default_size) if string == '' else parse_positive_int(string) num_rows = my_prompt(str_prompt.format('rows'), fcn_parse) num_cols = my_prompt(str_prompt.format('columns'), fcn_parse) # Should we play on a torus? fcn_parse_torus = lambda string: (True, False) if string == '' else parse_yes_no(string) on_torus = my_prompt("Make the board a torus (a la Pac-Man)? y/[n]: ", parse_yes_no) # Initialize a random game. game = GameOfLife(num_rows, num_cols, on_torus = on_torus) game.randomize_board() # ======================================================================== # A simple GUI demo # ======================================================================== # # Draw the board we created above, and update it every 250 milliseconds as long # as there is life on the board. No additional interaction is supported. # Create a canvas for drawing to. master = tk.Tk() master.title("Conway's Game of Life") w = tk.Canvas(master, width = 10 * num_cols, height = 10 * num_rows) w.pack() # Create the rectangles with which we'll draw the game.