469,934 Members | 2,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

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 9827
Menu widgets have an index, used to get/set their properties
There must be more elegant solutions, but this should work :

from Tkinter import *


def hello():
print "hello !"

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

menubar = Menu(root)


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)


# display the menu
----------------------Hope this helps,
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Humpty Dumpty | last post: by
2 posts views Thread by Stewart Midwinter | last post: by
3 posts views Thread by John Pote | last post: by
5 posts views Thread by Paul Rubin | last post: by
6 posts views Thread by Bob Greschke | last post: by
6 posts views Thread by Gigs_ | last post: by
2 posts views Thread by Kevin Walzer | last post: by
1 post views Thread by =?Utf-8?B?QW5kcmV3?= | last post: by
3 posts views Thread by Eric Brunel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.