summaryrefslogtreecommitdiff
path: root/graphics.py
diff options
context:
space:
mode:
authoryuzu-eva <stevenhu@web.de>2024-11-11 15:52:22 +0100
committeryuzu-eva <stevenhu@web.de>2024-11-11 15:52:22 +0100
commit696199a0227cfccb2247978b1ba8c1b03f1ae26d (patch)
tree493c3f65fdb65634c1577529bcfbf76356d9ec4f /graphics.py
initial commit
Diffstat (limited to 'graphics.py')
-rw-r--r--graphics.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/graphics.py b/graphics.py
new file mode 100644
index 0000000..3e4a745
--- /dev/null
+++ b/graphics.py
@@ -0,0 +1,43 @@
+from tkinter import Tk, BOTH, Canvas, Frame, Button
+
+class Window:
+ def __init__(self, width, height):
+ self.__root = Tk()
+ self.__root.title("Maze Solver")
+ self.__canvas = Canvas(self.__root, bg="white", height=height, width=width)
+ self.__canvas.pack(fill=BOTH, expand=1)
+ self.__is_running = False
+ self.__root.protocol("WM_DELETE_WINDOW", self.close)
+ self.__button = Button(self.__root, text="Close", command=self.close)
+ self.__button.pack()
+
+ def redraw(self):
+ self.__root.update_idletasks()
+ self.__root.update()
+
+ def wait_for_close(self):
+ self.__is_running = True
+ while(self.__is_running):
+ self.redraw()
+
+ def close(self):
+ self.__is_running = False
+
+ def draw_line(self, line, fill_color="black"):
+ line.draw(self.__canvas, fill_color)
+
+class Point:
+ def __init__(self, x, y):
+ self.x = x
+ self.y = y
+
+class Line:
+ def __init__(self, start, end):
+ self.start = start
+ self.end = end
+
+ def draw(self, canvas, fill_color):
+ canvas.create_line(
+ self.start.x, self.start.y, self.end.x, self.end.y, fill=fill_color, width=2
+ )
+