From ccdffe00bf88ce0d04a52987d6152b38f8448453 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Mon, 12 Feb 2024 20:04:55 +0000 Subject: [PATCH] fix: set missing attributes to the Canvas Add missing attributes to the Canvas including it's size. --- graphics.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/graphics.py b/graphics.py index 5e8f868..b9cd08d 100644 --- a/graphics.py +++ b/graphics.py @@ -1,5 +1,6 @@ from tkinter import Tk, BOTH, Canvas + class Point: """ Point represents the position of a point. @@ -37,20 +38,20 @@ class Window: """ def __init__(self, width: int, height: int): - self.width = width - self.height = height - self.__root = Tk() self.__root.title("Maze Solver") - self.__root.geometry(f"{self.width}x{self.height}") - - self.canvas = Canvas() - self.canvas.pack() - - self.is_running = False - self.__root.protocol("WM_DELETE_WINDOW", self.close) + self.__canvas = Canvas(self.__root) + self.__canvas.config( + bg="white", + height=height, + width=width, + ) + self.__canvas.pack() + + self.__is_running = False + def redraw(self): """ redraw redraws all the graphics in the window. @@ -63,18 +64,18 @@ class Window: wait_for_close continuously redraws the window until it is set to close. """ - self.is_running = True - while self.is_running: + self.__is_running = True + while self.__is_running: self.redraw() def draw_line(self, line: Line, fill_colour: str): """ draw_line draws a line on the canvas. """ - line.draw(self.canvas, fill_colour) + line.draw(self.__canvas, fill_colour) def close(self): """ close sets the window to close. """ - self.is_running = False + self.__is_running = False