Apr-16-2024, 08:19 PM
(This post was last modified: Apr-17-2024, 01:27 AM by deanhystad.)
That is not a feature that option menu supports. You cannot add a submenu to one of the options, because the options are radio buttons. To have submenus you need the option to be menus.
OptionMenu is really a convenience class for making a menu button with a menu of radio buttons. Here's an example of making an OptionMenu-like thing that supports cascading.
https://stackoverflow.com/questions/2435...-be-nested
It wouldn't be difficult to use this code as a starting point for making your own CascadedOptionMenu class.
I don't see how such a thing could be used to select 2 options as it only has 1 value. The cascading being more a mechanism for organizing the values than adding structure to the result.
You could organize your options to get two values using a regular option menu like this:
OptionMenu is really a convenience class for making a menu button with a menu of radio buttons. Here's an example of making an OptionMenu-like thing that supports cascading.
https://stackoverflow.com/questions/2435...-be-nested
It wouldn't be difficult to use this code as a starting point for making your own CascadedOptionMenu class.
I don't see how such a thing could be used to select 2 options as it only has 1 value. The cascading being more a mechanism for organizing the values than adding structure to the result.
You could organize your options to get two values using a regular option menu like this:
import tkinter as tk options = { "1 A": (1, "A"), "1 B": (1, "B"), "1 C": (1, "C"), "2 A": (2, "A"), "2 B": (2, "B"), "2 C": (2, "C"), "3": 3, "4": 4, } root = tk.Tk() var = tk.StringVar(root, list(options)[0]) menu = tk.OptionMenu(root, var, *list(options)) menu.pack(padx=50, pady=50) var.trace_add("write", lambda x, y, z: print(var.get(), options[var.get()])) root.mainloop()