Apr-04-2020, 08:11 AM
I like to access a subitem e.g. 'Save' in my tkinter Menu (see code below) to activate or deactivate it.
I can access and deactivate all "first level" items like 'Main', 'File' or 'Test' - therefore I found some examples already e.g.:
I searched a lot already, but can't find a working solution anywhere. The only one I found is this, but it gives me an type error all time:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1643, in cget
return self.tk.call(self._w, 'cget', '-' + key)
TypeError: can only concatenate str (not "int") to str
Thank you for any help on this!
I can access and deactivate all "first level" items like 'Main', 'File' or 'Test' - therefore I found some examples already e.g.:
self.menu.entryconfig("File", state="normal")but I still can not reach the "second level" items e.g. 'Save'
I searched a lot already, but can't find a working solution anywhere. The only one I found is this, but it gives me an type error all time:
self.menu[1].entryconfigure('Save', state='disabled') self.menu[1].entryconfigure('Save', state=DISABLED) self.menu[1].entryconfigure(1)Error:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1643, in cget
return self.tk.call(self._w, 'cget', '-' + key)
TypeError: can only concatenate str (not "int") to str
Thank you for any help on this!
def createMenu(self): self.menu = Menu(self.tk) self.tk.config(menu=self.menu) Main = Menu(self.menu) Main.add_command(label="StartScreen", command=self.menuStartScreen) Main.add_separator() Main.add_command(label="Settings", command=self.menuSettings) Main.add_separator() Main.add_command(label="Exit", command=self.client_exit) self.menu.add_cascade(label="Main", menu=Main) File = Menu(self.menu) File.add_command(label="Open", command=self.menuOpenFile) File.add_command(label="Save", command=self.menuSaveFile) File.add_separator() File.add_command(label="Print", command=self.menuPrint) self.menu.add_cascade(label="File", menu=File) Test = Menu(self.menu) Test.add_command(label="Test", command=self.menuTest) self.menu.add_cascade(label="Test", menu=Test)