[Tkinter-discuss] Disabling menu things

Bob Greschke bob at passcal.nmt.edu
Thu Dec 21 21:00:56 CET 2006

In this context:

from Tkinter import *

Root = Tk()

def about():
    # Whatever

def progQuitter():
    # Whatever

def makeMenu(Win):
    global Fi   # or most likely a dictionary that achieves the same thing
    global Hp
    global Top
    Top = Menu(Win)
    Win.configure(menu = Top)
    Fi = Menu(Top, tearoff = 0)
    Top.add_cascade(label = "File", menu = Fi)
    Fi.add_command(label = "Quit", command = progQuitter)
    Hp = Menu(Top, tearoff = 0)
    Top.add_cascade(label = "Help", menu = Hp)
    Hp.add_command(label = "About", command = about)


I want to write a function like

    def disableMenu("File", "Quit")
        # Finds the Quit item in File cascade and sets its state to DISABLED

How would disableMenu() entrycget() through the menu items to find the index 
of the "Quit" item?  How do I get a list of the cascades ("File", "Help" - 
just looping through Top.entrycget(i, "label") seems to do that) and then a 
list of the items in those cascades ("Quit", "About")?

As an aside

    print Fi.entrycget(1, "label")

seems to work, but (2, "label") doesn't.  It says "-label" is an unknown 
option.  I guess I don't know what I'm doing. :)



More information about the Tkinter-discuss mailing list