[Tutor] Changing menu "title" using Tkinter

André Roberge andre.roberge at ns.sympatico.ca
Mon Oct 4 11:21:58 CEST 2004


First, my apologies for the wrong subject line in my previous message,
and thank you to Kent Johnson for his useful pointer.

Moving along....
I would like to change the label 'File' to 'Fichier' in the following 
example.
I've tried various options, but with no success. 

Any help would be greatly appreciated.

André Roberge

================
from Tkinter import *
from tkFileDialog import askopenfilename
 
def makemenu(self):
    top = Menu(self)
    self.config(menu=top)
    
    def changeLang():
        if v.get() == 'fr':
            fileMenu.entryconfig(0, label='Ouvrir')
            fileMenu.entryconfig(1, label='Quitter')
#  --> here is where I would like to set the label
        else:
            fileMenu.entryconfig(0, label='Open')
            fileMenu.entryconfig(1, label='Quit')          

    def onOpen():
        filename = askopenfilename()
        msg['text'] = filename
    fileMenu = Menu(top, tearoff=0)
    fileMenu.add_command(label='Open', command=onOpen)
    fileMenu.add_command(label='Quit', command=self.quit)

# the following is the label that I would like to change
    top.add_cascade(label='File', menu=fileMenu)

    otherMenu = Menu(top, tearoff=0)

# I would like eventually to change the following label also...
    top.add_cascade(label='Other', menu=otherMenu)  

    LANGUAGES = [
        ('English', 'en'),
        ('Francais', 'fr') ]
    v = StringVar()
    v.set('en') # initialize
    for text, language in LANGUAGES:
        lang = Radiobutton(root, text=text, variable=v, value=language,
                           command=changeLang)
        lang.pack(anchor=W)

    msg = Label(root, text='test')
    msg.pack()
    
if __name__ == '__main__':
    root = Tk()
    makemenu(root)
    root.mainloop()


More information about the Tutor mailing list