From 7928434cc0d55dda766a7733926b12b2ef67a50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Doubravsk=C3=BD?= Date: Fri, 5 Sep 2025 10:29:23 +0200 Subject: [PATCH] Simple GUI --- Tagger.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/Tagger.py b/Tagger.py index 4c4e7f7..3914aa8 100644 --- a/Tagger.py +++ b/Tagger.py @@ -1 +1,73 @@ -print("Test") \ No newline at end of file +import tkinter as tk +from tkinter import ttk + +def main(): + root = tk.Tk() + root.title("Ukázka rozložení") + root.geometry("800x600") + + # ==== MENU ==== + menu_bar = tk.Menu(root) + root.config(menu=menu_bar) + + file_menu = tk.Menu(menu_bar, tearoff=0) + file_menu.add_command(label="Otevřít") + file_menu.add_command(label="Ukončit", command=root.quit) + menu_bar.add_cascade(label="Soubor", menu=file_menu) + + # ==== HLAVNÍ RÁM ==== + main_frame = tk.Frame(root) + main_frame.pack(fill="both", expand=True) + + main_frame.columnconfigure(0, weight=1) + main_frame.columnconfigure(1, weight=2) + main_frame.rowconfigure(0, weight=1) + + # ==== VLEVO: STROM ==== + tree = ttk.Treeview(main_frame) + tree.grid(row=0, column=0, sticky="nsew", padx=2, pady=2) + + root_node = tree.insert("", "end", text="Root") + tree.insert(root_node, "end", text="Child 1") + tree.insert(root_node, "end", text="Child 2") + tree.item(root_node, open=True) + + # ==== VPRAVO: SEZNAM ==== + listbox = tk.Listbox(main_frame) + listbox.grid(row=0, column=1, sticky="nsew", padx=2, pady=2) + + for i in range(1, 21): + listbox.insert("end", f"Položka {i}") + + # ==== STAVOVÝ ŘÁDEK ==== + status_bar = tk.Label(root, text="Připraven", anchor="w", relief="sunken") + status_bar.pack(side="bottom", fill="x") + + # ==== KONTEXTOVÁ MENU ==== + tree_menu = tk.Menu(root, tearoff=0) + tree_menu.add_command(label="Akce na stromu", command=lambda: status_bar.config(text="Klikl jsi na strom")) + + list_menu = tk.Menu(root, tearoff=0) + list_menu.add_command(label="Akce na seznamu", command=lambda: status_bar.config(text="Klikl jsi na seznam")) + + # ==== HANDLERY ==== + def tree_right_click(event): + item_id = tree.identify_row(event.y) + if item_id: # klik na uzel + tree.selection_set(item_id) + tree_menu.tk_popup(event.x_root, event.y_root) + + def list_right_click(event): + index = listbox.nearest(event.y) + if index >= 0: # klik na položku + listbox.selection_clear(0, "end") + listbox.selection_set(index) + list_menu.tk_popup(event.x_root, event.y_root) + + tree.bind("", tree_right_click) + listbox.bind("", list_right_click) + + root.mainloop() + +if __name__ == "__main__": + main()