Python Forum
access subitem in tkinter Menu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
access subitem in tkinter Menu
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.:"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:[1].entryconfigure('Save', state='disabled')[1].entryconfigure('Save', state=DISABLED)[1].entryconfigure(1)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/", line 1643, in cget
return, 'cget', '-' + key)
TypeError: can only concatenate str (not "int") to str

Thank you for any help on this!

  def createMenu(self): = Menu(

        Main = Menu(
        Main.add_command(label="StartScreen", command=self.menuStartScreen)
        Main.add_command(label="Settings", command=self.menuSettings)
        Main.add_command(label="Exit", command=self.client_exit)"Main", menu=Main)

        File = Menu(
        File.add_command(label="Open", command=self.menuOpenFile)
        File.add_command(label="Save", command=self.menuSaveFile)
        File.add_command(label="Print", command=self.menuPrint)"File", menu=File)

        Test = Menu(
        Test.add_command(label="Test", command=self.menuTest)"Test", menu=Test)
Why not keep a handle to the menus?
from tkinter import *

class MyProgram:
    def __init__(self): = Tk()
        = Menu(

        self.main_menu = Menu(, tearoff=0)
        self.main_menu .add_command(label="StartScreen")
        self.main_menu .add_command(label="Settings")
        self.main_menu .add_command(label="Exit")"Main", menu=self.main_menu )

        self.file_menu = Menu(, tearoff=0)
        self.file_menu.add_command(label="Print")"File", menu=self.file_menu)

        self.test_menu = Menu(, tearoff=0)
        self.test_menu.add_command(label="Test")"Test", menu=self.test_menu)

demo = MyProgram()
demo.file_menu.entryconfigure("Save", state=DISABLED)

Great idea!
Thanks a lot!!! - works perfect this way...

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter menu font size -method to change tonycat 2 689 Oct-11-2020, 02:43 AM
Last Post: tonycat
  Nesting menu buttons tkinter for python Mocap 1 892 Jul-18-2019, 11:46 AM
Last Post: metulburr
  Tkinter Gui Menu Addition Error whisperquiet 2 965 Jan-04-2019, 09:29 PM
Last Post: whisperquiet
  [Tkinter] Tkinter optionmenu child menu position showing 0,0 thatguy14 2 2,178 Jun-15-2018, 10:42 AM
Last Post: thatguy14
  printing option menu variable in label in Tkinter SmokerX 1 3,820 Jan-18-2018, 07:36 PM
Last Post: SmokerX

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020