|
1 | 1 | from copy import deepcopy |
2 | | -from tkinter import * |
| 2 | +import tkinter as tk |
3 | 3 |
|
4 | 4 | from search import * |
5 | 5 | from utils import PriorityQueue |
@@ -28,7 +28,7 @@ def create_map(root): |
28 | 28 | width = 750 |
29 | 29 | height = 670 |
30 | 30 | margin = 5 |
31 | | - city_map = Canvas(root, width=width, height=height) |
| 31 | + city_map = tk.Canvas(root, width=width, height=height) |
32 | 32 | city_map.pack() |
33 | 33 |
|
34 | 34 | # Since lines have to be drawn between particular points, we need to list |
@@ -274,31 +274,31 @@ def make_rectangle(map, x0, y0, margin, city_name): |
274 | 274 | x0 - 2 * margin, |
275 | 275 | y0 - 2 * margin, |
276 | 276 | text=city_name, |
277 | | - anchor=E) |
| 277 | + anchor=tk.E) |
278 | 278 | else: |
279 | 279 | map.create_text( |
280 | 280 | x0 - 2 * margin, |
281 | 281 | y0 - 2 * margin, |
282 | 282 | text=city_name, |
283 | | - anchor=SE) |
| 283 | + anchor=tk.SE) |
284 | 284 | city_coord.update({city_name: rect}) |
285 | 285 |
|
286 | 286 |
|
287 | 287 | def make_legend(map): |
288 | 288 | rect1 = map.create_rectangle(600, 100, 610, 110, fill="white") |
289 | | - text1 = map.create_text(615, 105, anchor=W, text="Un-explored") |
| 289 | + text1 = map.create_text(615, 105, anchor=tk.W, text="Un-explored") |
290 | 290 |
|
291 | 291 | rect2 = map.create_rectangle(600, 115, 610, 125, fill="orange") |
292 | | - text2 = map.create_text(615, 120, anchor=W, text="Frontier") |
| 292 | + text2 = map.create_text(615, 120, anchor=tk.W, text="Frontier") |
293 | 293 |
|
294 | 294 | rect3 = map.create_rectangle(600, 130, 610, 140, fill="red") |
295 | | - text3 = map.create_text(615, 135, anchor=W, text="Currently Exploring") |
| 295 | + text3 = map.create_text(615, 135, anchor=tk.W, text="Currently Exploring") |
296 | 296 |
|
297 | 297 | rect4 = map.create_rectangle(600, 145, 610, 155, fill="grey") |
298 | | - text4 = map.create_text(615, 150, anchor=W, text="Explored") |
| 298 | + text4 = map.create_text(615, 150, anchor=tk.W, text="Explored") |
299 | 299 |
|
300 | 300 | rect5 = map.create_rectangle(600, 160, 610, 170, fill="dark green") |
301 | | - text5 = map.create_text(615, 165, anchor=W, text="Final Solution") |
| 301 | + text5 = map.create_text(615, 165, anchor=tk.W, text="Final Solution") |
302 | 302 |
|
303 | 303 |
|
304 | 304 | def tree_search(problem): |
@@ -622,51 +622,50 @@ def reset_map(): |
622 | 622 |
|
623 | 623 | # TODO: Add more search algorithms in the OptionMenu |
624 | 624 | if __name__ == "__main__": |
625 | | - global algo, start, goal, next_button |
626 | | - root = Tk() |
| 625 | + root = tk.Tk() |
627 | 626 | root.title("Road Map of Romania") |
628 | 627 | root.geometry("950x1150") |
629 | | - algo = StringVar(root) |
630 | | - start = StringVar(root) |
631 | | - goal = StringVar(root) |
| 628 | + algo = tk.StringVar(root) |
| 629 | + start = tk.StringVar(root) |
| 630 | + goal = tk.StringVar(root) |
632 | 631 | algo.set("Breadth-First Tree Search") |
633 | 632 | start.set('Arad') |
634 | 633 | goal.set('Bucharest') |
635 | 634 | cities = sorted(romania_map.locations.keys()) |
636 | | - algorithm_menu = OptionMenu( |
| 635 | + algorithm_menu = tk.OptionMenu( |
637 | 636 | root, |
638 | 637 | algo, "Breadth-First Tree Search", "Depth-First Tree Search", |
639 | 638 | "Breadth-First Graph Search", "Depth-First Graph Search", |
640 | 639 | "Uniform Cost Search", "A* - Search") |
641 | | - Label(root, text="\n Search Algorithm").pack() |
| 640 | + tk.Label(root, text="\n Search Algorithm").pack() |
642 | 641 | algorithm_menu.pack() |
643 | | - Label(root, text="\n Start City").pack() |
644 | | - start_menu = OptionMenu(root, start, *cities) |
| 642 | + tk.Label(root, text="\n Start City").pack() |
| 643 | + start_menu = tk.OptionMenu(root, start, *cities) |
645 | 644 | start_menu.pack() |
646 | | - Label(root, text="\n Goal City").pack() |
647 | | - goal_menu = OptionMenu(root, goal, *cities) |
| 645 | + tk.Label(root, text="\n Goal City").pack() |
| 646 | + goal_menu = tk.OptionMenu(root, goal, *cities) |
648 | 647 | goal_menu.pack() |
649 | | - frame1 = Frame(root) |
650 | | - next_button = Button( |
| 648 | + frame1 = tk.Frame(root) |
| 649 | + next_button = tk.Button( |
651 | 650 | frame1, |
652 | 651 | width=6, |
653 | 652 | height=2, |
654 | 653 | text="Next", |
655 | 654 | command=on_click, |
656 | 655 | padx=2, |
657 | 656 | pady=2, |
658 | | - relief=GROOVE) |
659 | | - next_button.pack(side=RIGHT) |
660 | | - reset_button = Button( |
| 657 | + relief=tk.GROOVE) |
| 658 | + next_button.pack(side=tk.RIGHT) |
| 659 | + reset_button = tk.Button( |
661 | 660 | frame1, |
662 | 661 | width=6, |
663 | 662 | height=2, |
664 | 663 | text="Reset", |
665 | 664 | command=reset_map, |
666 | 665 | padx=2, |
667 | 666 | pady=2, |
668 | | - relief=GROOVE) |
669 | | - reset_button.pack(side=RIGHT) |
670 | | - frame1.pack(side=BOTTOM) |
| 667 | + relief=tk.GROOVE) |
| 668 | + reset_button.pack(side=tk.RIGHT) |
| 669 | + frame1.pack(side=tk.BOTTOM) |
671 | 670 | create_map(root) |
672 | 671 | root.mainloop() |
0 commit comments