-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.py
54 lines (40 loc) · 1.19 KB
/
window.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
49
50
51
52
53
from tkinter import Tk, BOTH, Canvas
class Window:
def __init__(self, width: int, height: int):
self.root = Tk()
self.root.title: str = "Maze Solver"
self.canvas = Canvas(height=height, width=width, bg="black")
self.canvas.pack()
self.running: bool = False
self.root.protocol("WM_DELETE_WINDOW", self.close)
def redraw(self):
self.root.update_idletasks()
self.root.update()
def wait_for_close(self):
self.running = True
while self.running:
self.redraw()
def close(self):
self.running = False
def draw_line(self, line, fill_color):
line.draw(self.canvas, fill_color)
class Point:
def __init__(self, x, y):
# horizontal
self.x: int = x
# vertical
self.y: int = y
class Line:
def __init__(self, point_a, point_b):
self.point_a = point_a
self.point_b = point_b
def draw(self, canvas, fill_color):
canvas.create_line(
self.point_a.x,
self.point_a.y,
self.point_b.x,
self.point_b.y,
fill=fill_color,
width=2
)
canvas.pack()