-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
61 lines (51 loc) · 2.84 KB
/
gui.py
File metadata and controls
61 lines (51 loc) · 2.84 KB
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
59
60
61
import tkinter as tk
class GUI:
def __init__(self, tokenize_command, parse_command, show_grammar_rules, clear_command, show_next_command, show_previous_command):
self.root = tk.Tk()
self.root.title("Token Parser")
self.root.geometry("600x600") # Set initial window size
# Buttons for Next and Previous
self.navigation_frame = tk.Frame(self.root)
self.navigation_frame.pack(pady=5)
self.next_button = tk.Button(self.navigation_frame, text="Next", command=show_next_command)
self.next_button.pack(side="left", padx=(5, 0), anchor="w") # Anchored to the west (leftmost)
self.previous_button = tk.Button(self.navigation_frame, text="Previous", command=show_previous_command)
self.previous_button.pack(side="right", padx=(0, 5), anchor="e") # Anchored to the east (rightmost)
# Input Box
self.input_frame = tk.Frame(self.root)
self.input_frame.pack(pady=5, padx=10, fill="both")
self.input_label = tk.Label(self.input_frame, text="Input:")
self.input_label.pack(side="left", padx=(0, 10))
self.input_box = tk.Text(self.input_frame, height=10, width=50) # Adjusted size
self.input_box.pack(fill="both", expand=False)
# Output Box
self.output_frame = tk.Frame(self.root)
self.output_frame.pack(pady=5, padx=10, fill="both", expand=True)
self.output_label = tk.Label(self.output_frame, text="Output:")
self.output_label.pack(side="left", padx=(0, 10))
self.output_box = tk.Text(self.output_frame, height=20, width=50) # Adjusted size
self.output_box.pack(fill="both", expand=True)
# Buttons
self.button_frame = tk.Frame(self.root)
self.button_frame.pack(pady=5)
self.tokenize_button = tk.Button(self.button_frame, text="Tokenize", command=tokenize_command)
self.tokenize_button.pack(side="left", padx=5)
self.parse_button = tk.Button(self.button_frame, text="Parse", command=parse_command)
self.parse_button.pack(side="left", padx=5)
self.grammar_button = tk.Button(self.button_frame, text="Grammar", command=show_grammar_rules) # Add this button
self.grammar_button.pack(side="left", padx=5)
self.clear_button = tk.Button(self.button_frame, text="Clear", command=clear_command)
self.clear_button.pack(side="left", padx=5)
def get_input_text(self):
return self.input_box.get("1.0", "end-1c")
def set_input_text(self, text):
self.input_box.delete("1.0", "end")
self.input_box.insert("end", text)
def set_output_text(self, text):
self.output_box.delete("1.0", "end")
self.output_box.insert("end", text)
def clear_boxes(self):
self.input_box.delete("1.0", "end")
self.output_box.delete("1.0", "end")
def run(self):
self.root.mainloop()