maze-solver/app.py
Dan Anglin 4c7e50ec39
checkpoint: Add side panel
Add a side panel to allow users to interact with the app.
The generate button now generates the maze.
2024-02-17 20:06:09 +00:00

86 lines
2.5 KiB
Python

from tkinter import ttk, Tk, Canvas, StringVar, BooleanVar
from maze import Maze
from solver import Solver
from graphics import Graphics
class App(Tk):
def __init__(self):
super().__init__()
self.title("Maze Solver")
# Position the window to the centre of the screen
# screen_width = self._root.winfo_screenwidth()
# screen_height = self._root.winfo_screenheight()
# centre_x = int(screen_width/2 - width/2)
# centre_y = int(screen_height/2 - height/2)
# self._root.geometry(f"{width}x{height}+{centre_x}+{centre_y}")
# Styling
self.style = ttk.Style()
self.style.theme_use("clam")
self.background_colour = "white"
self.cell_grid_colour = "black"
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
self.canvas = Canvas(self)
self.canvas.config(
bg=self.background_colour,
width=800,
height=800
)
self.canvas.grid(column=1, row=0)
self.graphics = Graphics(self.canvas)
self.maze = Maze(
x_position=10,
y_position=10,
height=19,
width=19,
cell_height=40,
cell_width=40,
graphics=self.graphics,
)
self.solver = Solver(self.maze)
self.side_panel = self._create_side_panel()
self.side_panel.grid(column=0, row=0)
def _create_side_panel(self):
frame = ttk.Frame(self)
label = ttk.Label(frame)
label.config(text="Maze Solver", font=(None, 20))
label.pack()
generate = ttk.Button(
frame,
text="Generate maze",
command=self.maze.generate,
)
generate.pack()
algorithm = StringVar()
combobox = ttk.Combobox(frame, textvariable=algorithm)
algorithm_label = ttk.Label(frame, text="Searching algorithm:")
algorithm_label.pack()
combobox["values"] = ("Breadth-First Search", "Depth-First Search")
combobox["state"] = "readonly"
combobox.pack()
randomness = BooleanVar()
enable_randomness = ttk.Checkbutton(frame)
enable_randomness.config(
text="Enable Randomness",
variable=randomness,
onvalue=True,
offvalue=False,
)
enable_randomness.pack()
solve = ttk.Button(
frame,
text="Solve the maze",
)
solve.pack()
return frame