-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.py
58 lines (45 loc) · 1.73 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
49
50
51
52
53
54
55
56
57
58
from tkinter import Tk, BOTH, Canvas, Button, OptionMenu
class Window():
def __init__(self, width, height):
self.__root = Tk()
self.__root.title("MAZE SOLVER")
self.__root.protocol("WM_DELETE_WINDOW", self.close)
self.__canvas = Canvas(self.__root, bg="white", width=width,height=height)
self.__canvas.pack(fill=BOTH, expand=1)
self.__window_running = False
self.height = height
self.width = width
def redraw(self):
self.__root.update_idletasks()
self.__root.update()
def wait_for_close(self):
self.__window_running = True
while self.__window_running:
self.redraw()
def draw_line(self, line_class, fill_color="black"):
line_class.draw(self.__canvas, fill_color)
def return_canvas(self):
return self.__canvas
def create_widget_window(self, x, y, height, width, widget):
widget.config(bg="White")
self.__canvas.create_window(x ,y , height=height, width=width, window=widget)
def clear_canvas(self):
self.__canvas.delete("all")
def close(self):
self.__window_running = False
class Point():
def __init__(self,x,y):
self.x = x
self.y = y
def __eq__(self, other):
return self.x == other.x and self.y == other.y
class Line():
def __init__(self, point_1, point_2):
self.point_1 = point_1
self.point_2 = point_2
def __eq__(self, other):
return self.point_1 == other.point_1 and self.point_2 == other.point_2
def draw(self, canvas, fill_colour="black"):
canvas.create_line(
self.point_1.x, self.point_1.y, self.point_2.x, self.point_2.y , fill=fill_colour, width = 2
)