[Tutor] Re: Tutor Digest, Vol 8, Issue 2

Kent Johnson kent_johnson at skillsoft.com
Mon Oct 4 06:17:17 CEST 2004

You can use file.entryconfig() to set properties of the menu commands. One 
way to do what you want is to use the command for the radio buttons to set 
the correct menu text. Note that the file menu has to be set to tearoff=0 
for this to work. You could also use a postcommand property on the file 
menu to do this, for an example see 
http://www.pythonware.com/library/tkinter/introduction/x5819-patterns.htm .

from Tkinter import *
from tkFileDialog import askopenfilename

def onOpen():
    filename = askopenfilename()

if __name__ == '__main__':
    root = Tk()

    top = Menu(root)
    fileMenu = Menu(top, tearoff=0)
    fileMenu.add_command(label='Open', command=onOpen)
    top.add_cascade(label='File', menu=fileMenu)

        ('English', 'en', 'Open'),
        ('Francais', 'fr', 'Ouvrir') ]
    v = StringVar()

    for text, language, openText in LANGUAGES:
        lang = Radiobutton(root, text=text,
                        variable=v, value=language,
                        command=lambda: fileMenu.entryconfig(0, 


At 10:53 PM 10/3/2004 -0300, André Roberge wrote:
>I would like to know how dynamically change a label ('Open') in the file menu
>below to ('Ouvrir') when the selected language is Francais/French ('fr')
>in the Radiobutton choice.
>Thanks in advance,
>André Roberge
>from Tkinter import *
>from tkFileDialog import askopenfilename
>def onOpen():
>    filename = askopenfilename()
>def makemenu(self):
>    top = Menu(self)
>    self.config(menu=top)
>    file = Menu(top)
>    file.add_command(label='Open', command=onOpen)
>    top.add_cascade(label='File', menu=file)
>if __name__ == '__main__':
>    root = Tk()
>    makemenu(root)
>    LANGUAGES = [
>        ('English', 'en'),
>        ('Francais', 'fr') ]
>    v = StringVar()
>    v.set('en')
>    for text, language in LANGUAGES:
>        lang = Radiobutton(root, text=text,
>                        variable=v, value=language)
>        lang.pack(anchor=W)
>    root.mainloop()
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list