473,382 Members | 1,290 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,382 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 3557
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.