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()