file add_command(label='new 'command=notdoneunderline= file add_command(label='open 'command=notdoneunderline= file add_command(label='quit'command=win quitunderline= top add_cascade(label='file'menu=fileunderline= edit menu(toptearoff=falseedit add_command(label='cut'edit add_command(label='paste'edit add_separator(top add_cascade(label='edit'command=notdonecommand=notdoneunderline= underline= menu=editunderline= submenu menu(edittearoff=truesubmenu add_command(label='spam'command=win quitunderline= submenu add_command(label='eggs'command=notdoneunderline= edit add_cascade(label='stuff'menu=submenuunderline= if __name__ ='__main__'root tk(or toplevel(root title('menu_win'set window-mgr info makemenu(rootassociate menu bar msg label(roottext='window menu basics'add something below msg pack(expand=yesfill=bothmsg config(relief=sunkenwidth= height= bg='beige'root mainloop( lot of code in this file is devoted to setting callbacks and suchso it might help to isolate the bits involved with the menu tree-building process for the file menuit' done like thistop menu(winwin config(menu=topfile menu(toptop add_cascade(label='file'menu=fileattach menu to window cross-link window to menu attach menu to top menu cross-link parent to child apart from building up the menu object treethis script also demonstrates some of the most common menu configuration optionsseparator lines the script makes separator in the edit menu with add_separatorit' just line used to set off groups of related entries tear-offs the script also disables menu tear-offs in the edit pull down by passing tearoff=false widget option to menu tear-offs are dashed lines that appear by default at the top of tkinter menus and create new window containing the menu' contents when clicked they can be convenient shortcut device (you can click items in the tear-off window right awaywithout having to navigate through menu trees)but they are not widely used on all platforms keyboard shortcuts the script uses the underline option to make unique letter in menu entry keyboard shortcut it gives the offset of the shortcut letter in the entry' label string menus