Cascading menus with Tk
Peter Otten
__peter__ at web.de
Fri May 20 07:42:06 EDT 2005
michelle wrote:
> What I am trying to do is add cascading menus to a Tk menu widget like:
>
> File
> New...
> ---> Router
> ---> Firewall
> Open
> ----
> Exit
Just add the submenu with the "Router" and "Firewall" entries to the
filemenu in the same way you added the submenu with the "New", "Open", and
"Exit" entries to the menu bar:
> mainWindow = Tk()
> mainWindow.title("myApp")
>
> # create a menu
> menubar = Menu(mainWindow)
> mainWindow.config(menu=menubar)
>
> filemenu = Menu(menubar)
> menubar.add_cascade(label="File", menu=filemenu)
new_menu = Menu(filemenu)
new_menu.add_command(label="Router")
new_menu.add_command(label="Firewall")
filemenu.add_cascade(label="New...", menu=new_menu)
> filemenu.add_command(label="Open...", command = openFileDialog)
> filemenu.add_separator()
> filemenu.add_command(label="Exit", command = mainWindow.destroy)
Peter
More information about the Python-list
mailing list