def create_board_canvas(board): """ Create a Tkinter Canvas for displaying a Nogogram solution. Return an instance of Tk filled as a grid. board: list of lists of {0, 1} """ canvas = Tk() LARGER_SIZE = 600 # dynamically set the size of each square based on cols and rows n_columns = len(board[0]) n_rows = len(board) divide = max(n_columns, n_rows) max_size = LARGER_SIZE / divide canvas_width = max_size * n_columns canvas_height = max_size * n_rows # create the intiial canvas with rows and columns grid canvas.canvas = Canvas( canvas, width=canvas_width, height=canvas_height, borderwidth=0, highlightthickness=0) canvas.title("Nonogram Display") canvas.canvas.pack(side="top", fill="both", expand="true") canvas.rows = len(board) canvas.columns = len(board[0]) canvas.cell_width = max_size canvas.cell_height = max_size canvas.rect = {} canvas.oval = {} insert_canvas_grid(canvas, board) return canvas