Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I recently started learning about tkinter menu's.

Is there any way to add sub-menus inside a sub-menu ? I mean , when I hover over a option in my menu , I want more sub-menus to show up. I'm very sorry if I am unclear , I don't know how do I explain this , but here's an image(GIF) of what I want .is there any way to achieve this in tkinter ?

Here's the code

from tkinter import *
root = Tk()
root.geometry("500x500")
mainmenu = Menu(root)
root.config(menu = mainmenu)
test_menu = Menu(mainmenu , tearoff = False)
mainmenu.add_cascade(label = "Test Menu" , menu = test_menu)
test_menu.add_command(label = "Show Sub-menus           ")
mainloop()

It would be great if anyone could help me out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
743 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can just keep going adding sub menus using add_cascade:

sub_menu = Menu(test_menu, tearoff=False)
sub_menu.add_command(label='Submenu item 1')
sub_menu.add_command(label='Submenu item 2')

test_menu.add_cascade(label = 'Sub menu', menu=sub_menu)

Tkinter window with a sub menu

sub_sub_menu = Menu(sub_menu, tearoff=False)
sub_sub_menu.add_command(label='Sub-submenu item 1')
sub_sub_menu.add_command(label='Sub-submenu item 2')

sub_menu.add_cascade(label='Sub-sub menu', menu=sub_sub_menu)

Tkinter window with a sub-sub menu


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...