Cascading menus with Tk

michelle miki at spam_me.net
Fri May 20 06:10:43 EDT 2005


Hi all,

I am new to Tk, or Python GUI programming and I seem to be stuck.  I
have looked about for help with Tk GUIs, but everything seems so terse
or incomplete?? I have been mostly using the "Introduction to Tkinter"
by Fredrik Lundh
(http://www.pythonware.com/library/tkinter/introduction/index.htm)

What I am trying to do is add cascading menus to a Tk menu widget like:

File
New...
---> Router
---> Firewall
Open
----
Exit

This seems simple enough, but I can't get it to work...the two
"add_cascade" methods (shown below), if used, run an endless loop that
is difficult to break:

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)
filemenu.add_command(label="New...")
filemenu.add_cascade(label="Router")
filemenu.add_cascade(label="Firewall")
filemenu.add_command(label="Open...", command = openFileDialog)
filemenu.add_separator()
filemenu.add_command(label="Exit", command = mainWindow.destroy)

helpmenu = Menu(menubar)
menubar.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="Online Help")
helpmenu.add_command(label="Help on the web")
helpmenu.add_separator()
helpmenu.add_command(label="About...", command = openAboutBox)

Any ideas??

Miki



More information about the Python-list mailing list