set combobox values to keys from dictionary

This commit is contained in:
Dan Anglin 2024-02-18 02:57:32 +00:00
parent 9bb23b6c6d
commit 8b55d28060
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638

10
app.py
View file

@ -43,7 +43,7 @@ class App(Tk):
self.solver = Solver(self.maze)
self.algorithm_map = {
self.search_algorithms = {
"Breadth-First Search": self.solver.solve_with_dfs_r,
"Depth-First Search": self.solver.solve_with_bfs_r,
}
@ -62,11 +62,13 @@ class App(Tk):
command=self.maze.generate,
)
generate.pack()
tuple_of_algorithms = tuple(self.search_algorithms.keys())
algorithm = StringVar()
combobox = ttk.Combobox(frame, textvariable=algorithm)
algorithm.set(tuple_of_algorithms[0])
algorithm_label = ttk.Label(frame, text="Searching algorithm:")
algorithm_label.pack()
combobox["values"] = ("Breadth-First Search", "Depth-First Search")
combobox = ttk.Combobox(frame, textvariable=algorithm)
combobox["values"] = tuple_of_algorithms
combobox["state"] = "readonly"
combobox.pack()
randomness = BooleanVar()
@ -82,7 +84,7 @@ class App(Tk):
frame,
text="Solve the maze",
command=lambda: self.solver.solve(
solve_method=self.algorithm_map[algorithm.get()],
solve_method=self.search_algorithms[algorithm.get()],
enable_random_direction=randomness.get(),
),
)