-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.py
48 lines (36 loc) · 1.33 KB
/
graphics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from tkinter import Tk, Canvas, BOTH
class Point():
def __init__(self, x, y) -> None:
self.x = x
self.y = y
class Line():
def __init__(self, point1: Point, point2: Point) -> None:
self.point1 = point1
self.point2 = point2
def draw(self, canvas: Canvas, fill_color: str):
canvas.create_line(
self.point1.x, self.point1.y, self.point2.x, self.point2.y, fill=fill_color, width=2
)
canvas.pack(fill=BOTH, expand=1)
class Window:
def __init__(self, width, height):
# Create root widget and assign a title
self.__root = Tk()
self.__root.title("Maze Solver")
self.__root.protocol("WM_DELETE_WINDOW", self.close)
# Create a canvas and pack it
self.__canvas = Canvas(self.__root, bg="black", height=height, width=width)
self.__canvas.pack(fill=BOTH, expand=1)
self.__running = False
def redraw(self):
self.__root.update_idletasks()
self.__root.update()
def wait_for_close(self):
self.__running = True
while self.__running:
self.redraw()
print("Window closed..")
def close(self):
self.__running = False
def draw_line(self, line: Line, fill_color: str = "white"):
line.draw(self.__canvas, fill_color)