473,396 Members | 1,771 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,396 software developers and data experts.

Tkinter: disable menu items while running

We have a Tkinter application which has a menubar with cascade
submenus. I would like to start the program with one of the
submenu items state=DISABLED, then change it to state=NORMAL
at a later time. I hope I just missed something obvious,
because I can't figure out how to change its state.

The problem comes about because the menu bar is built by several
add_cascade() calls. Each of the cascades, in turn, has
several add_command() calls. If the cascade in question was,
say, an object named Cas, then I could call Cas.entryconfigure().
However, I don't know how to get ahold of the objects
created by add_cascade() or add_command(). Do they live
somewhere accessible?

--
* Patrick L. Nolan *
* W. W. Hansen Experimental Physics Laboratory (HEPL) *
* Stanford University *
Jul 18 '05 #1
1 11524
Menu widgets have an index, used to get/set their properties
There must be more elegant solutions, but this should work :

----------------------
from Tkinter import *

root=Tk()

def hello():
print "hello !"

def toggle():
if submenu.entrycget(0,"state")=="normal":
submenu.entryconfig(0,state=DISABLED)
submenu.entryconfig(1,label="Speak please")
else:
submenu.entryconfig(0,state=NORMAL)
submenu.entryconfig(1,label="Quiet please")

menubar = Menu(root)

submenu=Menu(menubar,tearoff=0)

submenu2=Menu(submenu,tearoff=0)
submenu2.add_command(label="Hello", command=hello)

# this cascade will have index 0 in submenu
submenu.add_cascade(label="Say",menu=submenu2,stat e=DISABLED)
# these commands will have index 1 and 2
submenu.add_command(label="Speak please",command=toggle)
submenu.add_command(label="Exit", command=root.quit)

menubar.add_cascade(label="Test",menu=submenu)

# display the menu
root.config(menu=menubar)
root.mainloop()
----------------------Hope this helps,
Pierre
Jul 18 '05 #2

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...
2
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in...
3
by: John Pote | last post by:
I have a menu bar in a top level window as follows menuBar = Menu(rootWin) menuBar.add_command( label='Quit', command=rootWin.quit) configMenu = Menu(menuBar, tearoff=0)...
5
by: Paul Rubin | last post by:
I have a gui with a bunch of buttons, labels, the usual stuff. It uses the grid manager: gui = Frame() gui.grid() gui.Label(....).grid() # put some widgets into the gui ... # more widgets...
6
by: Bob Greschke | last post by:
Root.option_add("*?????*font", "Helvetica 12 bold") Want to get rid of the "font =": Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold") Does anyone know what ?????...
6
by: Gigs_ | last post by:
I'm writing text editor. How to enable/disable (cut, copy etc.) when text is selected/not selected
2
by: Kevin Walzer | last post by:
I'm porting a Tkinter application to wxPython and had a question about wxPython's event loop. The Tkinter app provides a GUI to a command-line tool. It gathers user input, and opens an...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hi, friends, I am using C#.net 2005 to create a windows application. It has menu items, such as File, etc. Under File, there are more menu items, such as New Files, Working Files, etc. Under...
3
by: Eric Brunel | last post by:
Hello all, I'm trying out Python 2.6 and I found what might be a bug in the Tkinter module. How can I report it? The possible bug is a traceback when trying to delete a menu item in a menu...
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?
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.