ragardner
ragardner

Reputation: 1975

Python tkinter error when changing menu label

I am trying to change a cascade label on a tkinter tk.Tk() menu but I am getting the error:

_tkinter.TclError: unknown option "-label"

To trigger the error you have to press "File" and then "Change"

try:
    import tkinter as tk
except:
    import Tkinter as tk


class app(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.menubar = tk.Menu(self)
        self.config(menu=self.menubar)
        self.cascade = tk.Menu(self.menubar,tearoff=0)
        self.menubar.add_cascade(label="File",menu=self.cascade)
        self.cascade.add_command(label="Change",command=self.change_cascade_label)

    def change_cascade_label(self):
        self.menubar.entryconfig(0,label="Edit")

run = app()
run.mainloop()

Upvotes: 2

Views: 555

Answers (1)

Kredns
Kredns

Reputation: 37201

You need to change the 0 to a 1 in the self.menubar.entryconfig line. The first parameter 1 has to be the index of the item you want to change, starting from 1.

Upvotes: 2

Related Questions