0

enter image description hereI try to create a menu like this in tkinter. Here is what I would like on this picture. In this Menu, I have categories (here on the picture for example General Options, Body Options, Neck Options...). When I click on a categories, a sub-list of others options appear (for example for the Neck Options, we can see Neck Wood, Number of frets, Neck Profile etc.). And if I click on one option, I want to selection one option (it could be a drop-down list or a toggle switch or checkbox, whatever allowing to choose something). For example here, in the option Fingerboard Radius, I can choose 14, 12, 10, 12-16.

I tried to embed toggle-switch and drop-down list in a treeview but it doesn't seem it is possible... I tried using tab but no, it is not what I want. Here is an example using drop-down-list :

import tkinter as tk

class GuitareDesignerApp:
    def __init__(self, root):
        self.root = root
        self.root.title("Guitare Designer")

        # Frame à gauche
        self.left_frame = tk.Frame(self.root, width=200, bg="gray")
        self.left_frame.pack(side="left", fill="both", expand=False)

        # Frame central
        self.center_frame = tk.Frame(self.root, bg="white")
        self.center_frame.pack(side="left", fill="both", expand=True)

        # Frame à droite
        self.right_frame = tk.Frame(self.root, width=200, bg="gray")
        self.right_frame.pack(side="left", fill="both", expand=False)

        # Catégories avec options
        self.categories = {
            "Options générales": ["Dextérité", "Marque"],
            "Body": ["Type de bois", "Forme"],
            "Neck": ["Type de bois", "Type de manche"],
            "Head": ["Type de tête", "Logo"],
            "Electronics": ["Micros", "Système électronique"],
            "Hardware": ["Chevalet", "Mécaniques"],
            "Export/Load": ["Exporter", "Charger"]
        }

        # Label pour les catégories
        self.category_labels = []
        for category in self.categories:
            label = tk.Label(self.left_frame, text=category, bg="gray", fg="white")
            label.pack(fill="x", pady=5)
            self.category_labels.append(label)

        # Menu déroulant pour les options
        self.option_menus = {}
        for category, options in self.categories.items():
            option_var = tk.StringVar(self.left_frame)
            option_var.set(options[0])  # Initialisation avec la première option
            menu = tk.OptionMenu(self.left_frame, option_var, *options)
            menu.pack(fill="x", padx=10)
            self.option_menus[category] = option_var

if __name__ == "__main__":
    root = tk.Tk()
    app = GuitareDesignerApp(root)
    root.mainloop()

and here another on with treeview :

import tkinter as tk
from tkinter import ttk

class App:
    def __init__(self, root):
        self.root = root
        self.root.title("Application")

        # Création de l'arbre
        self.tree = ttk.Treeview(root)
        self.tree.pack(side="left", fill="both", expand=True)
        self.tree.bind("<<TreeviewSelect>>", self.on_select)

        # Ajout des éléments à l'arbre
        general_node = self.tree.insert("", "end", text="général")
        body_node = self.tree.insert("", "end", text="body")

        self.tree.insert(general_node, "end", text="dextérité")
        self.tree.insert(general_node, "end", text="marque")

        self.tree.insert(body_node, "end", text="bois")
        self.tree.insert(body_node, "end", text="couleur")

        # Panneau droit
        self.right_frame = tk.Frame(root, bg="lightgrey", width=200)
        self.right_frame.pack(side="right", fill="both", expand=True)

        self.color_label = ttk.Label(self.right_frame, text="Couleur:")
        self.color_label.grid(row=2, column=0, sticky=tk.W)
        self.color_combo = ttk.Combobox(self.right_frame, values=["Noir", "Blanc", "Sunburst"])
        self.color_combo.grid(row=2, column=1)

    def on_select(self, event):
        selected_item = self.tree.selection()[0]
        selected_text = self.tree.item(selected_item, "text")

        if selected_text == "couleur":
            self.color_label.grid(row=2, column=0, sticky=tk.W)
            self.color_combo.grid(row=2, column=1)
        else:
            self.color_label.grid_forget()
            self.color_combo.grid_forget()

def main():
    root = tk.Tk()
    app = App(root)
    root.mainloop()

if __name__ == "__main__":
    main()
4
  • 1
    What have you tried so far? Commented May 2, 2024 at 16:19
  • I tried to embed toggle-switch and drop-down list in a treeview but it doesn't seem it is possible... Apparently I can't paste my differents scripts because we are limited in characters. But I wrote scripts with the treeview widget, and tried to put in the treeview the buttons, but it doens't work. I read apparently function tkinter can't embed other functions. I also try to use drop-down list to put a drop-down list inside another drop-down list, but obviously it doensn't work at all... Commented May 3, 2024 at 2:15
  • I mean to say, please edit your question to include a minimal reproducible example. We can't work on code we can't see, so it's always recommended to put relevant code in the body of your question. Commented May 3, 2024 at 12:06
  • 1
    OK, I put 2 examples in the main question ;). Commented May 3, 2024 at 12:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.