473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cascading menus with Tk

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/tk...tion/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
Jul 19 '05 #1
3 3558
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

Jul 19 '05 #2
michelle wrote:
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/tk...tion/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...")
I think you want these two options to be in a cascading menu like so:

newmenu = Menu(filemenu)
filemenu.add_cascade(label="New...", menu=newmenu)

newmenu.add_command(label="Router")
newmenu.add_command(label="Firewall")
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


Martin

Jul 19 '05 #3
Martin Franklin wrote:
michelle wrote:
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/tk...tion/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...")

I think you want these two options to be in a cascading menu like so:

newmenu = Menu(filemenu)
filemenu.add_cascade(label="New...", menu=newmenu)

newmenu.add_command(label="Router")
newmenu.add_command(label="Firewall")
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

Martin

Thank you, your code worked perfectly....

Miki
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Humpty Dumpty | last post by:
Hi folks, here's a challenge: I have a dynamically created cascading menu in Tkinter that can be quite large because it is created from a file. I tried using lazy creation so only the menu item...
7
by: Marci | last post by:
I found this script for cascading menus, however, I cannot reach the author to solve the bug I am having when I add a second menu to it. My problem is this: If I click on the first link, the...
1
by: Cindy Lee | last post by:
is it possible to have cascading menus like: http://www.cracky.net/JAVA/Navigation/cascading-menu.html With scrollbars added, so you can only see a few options at a time? On some of my options...
1
by: JMosey | last post by:
Not sure if this has been covered ( a google search came up pretty bare). I have a site that: - has multi-level cascading menus - floats center of the browser window - Will have fairly heavy...
1
by: Yavuz Bogazci | last post by:
hi, has someone a sample how to create cascading and database driven menues??? Help! I don't know where to begin! Thanks Yavuz Bogazci
5
by: MarkW | last post by:
I hope this is the correct place to post this: I am developing a web site for a e-commerce business I will be running. The site I'm setting up will be 50% store, 50% content. I'm not sure which...
1
by: arjun.zacharia | last post by:
Hi everyone, i want to implement a cascading menu in my application but do not want to reinvent the wheel. is there anybody here who might have written such stuff or could help me with somem...
1
by: support | last post by:
In dotNet, I want to have cascading pulldown menus. Hence, the items are: { a, b, cx, cy, cz, d}, but I don't want to show cx, cy, cz unless the user selected one of the c's. Does anyone know a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.