3 menus nested in the containers : Menu « Tkinker « Python Tutorial






3 menus nested in the containers
from Tkinter import * 

def notdone():  
    showerror('Not implemented', 'Not yet available') 
     
def makemenu(parent):
    menubar = Frame(parent)                        
    menubar.pack(side=TOP, fill=X)
    
    fbutton = Menubutton(menubar, text='File', underline=0)
    fbutton.pack(side=LEFT)
    file = Menu(fbutton)
    file.add_command(label='New...',  command=notdone,     underline=0)
    file.add_command(label='Open...', command=notdone,     underline=0)
    file.add_command(label='Quit',    command=parent.quit, underline=0)
    fbutton.config(menu=file)
     
    ebutton = Menubutton(menubar, text='Edit', underline=0)
    ebutton.pack(side=LEFT)
    edit = Menu(ebutton, tearoff=0)
    edit.add_command(label='Cut',     command=notdone,     underline=0)
    edit.add_command(label='Paste',   command=notdone,     underline=0)
    edit.add_separator()
    ebutton.config(menu=edit)
     
    submenu = Menu(edit, tearoff=0)
    submenu.add_command(label='Spam', command=parent.quit, underline=0)
    submenu.add_command(label='Eggs', command=notdone,     underline=0)
    edit.add_cascade(label='Stuff',   menu=submenu,        underline=0)
    return menubar
     
root = Tk()
for i in range(3):
    frm = Frame()  
    mnu = makemenu(frm)
    mnu.config(bd=2, relief=RAISED)
    frm.pack(expand=YES, fill=BOTH)
    Label(frm, bg='black', height=5, width=15).pack(expand=YES, fill=BOTH)
Button(root, text="Bye", command=root.quit).pack()
root.mainloop()








18.20.Menu
18.20.1.File menuFile menu
18.20.2.MenuBars with ChiocesMenuBars with Chioces
18.20.3.Menu commandMenu command
18.20.4.Add Menu item by adding commandAdd Menu item by adding command
18.20.5.Starndard File MenuStarndard File Menu
18.20.6.Context MenusContext Menus
18.20.7.Add action command to menu itemAdd action command to menu item
18.20.8.Frame-based menus: for top-levels and componentsFrame-based menus: for top-levels and components
18.20.9.3 menus nested in the containers3 menus nested in the containers
18.20.10.2 menus nested in one window2 menus nested in one window
18.20.11.Tk8.0 style top-level window menusTk8.0 style top-level window menus
18.20.12.3 popup windows with menus3 popup windows with menus
18.20.13.Option menuOption menu