title: Python: How can i get the selected element in a menu of menubar?
body: <p>So i was just improving the text editor that i made..
  The problem is that i want to get the clicked element of the menu inside my menubar of tkinter window..</p>
  <p><a href="https://i.stack.imgur.com/oJmH5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oJmH5.png" alt="enter image description here" /></a></p>
  <p>Here in this picture How can i get the clicked item &quot;C++ Compile&quot;?
  I am just unable to figure out how to solve this..</p>
  <p>Menu code:</p>
  <pre><code>Menubar = Menu(root, activebackground =&quot;#0084FF&quot;, activeforeground = &quot;#FFFFFF&quot;,bg = &quot;#FFFFFF&quot;, fg = &quot;#0084FF&quot; ,font = &quot;consolas&quot;)
  
  Filemenu = Menu(root, tearoff = 0)
  Filemenu.add_command(label=&quot;New&quot;,command=newTab)
  Filemenu.add_separator()
  Filemenu.add_command(label=&quot;Open&quot;, command=openFile)
  Filemenu.add_command(label=&quot;Save&quot;, command=saveFile)
  Filemenu.add_command(label=&quot;Save As&quot;, command=saveAsFile)
  Filemenu.add_separator()
  Filemenu.add_command(label=&quot;Close&quot;, command=deltab)
  Filemenu.add_separator()
  Filemenu.add_command(label=&quot;Exit&quot;, command=root.destroy)
  Menubar.add_cascade(label=&quot;File&quot;, menu=Filemenu)
  
  toolsMenu = Menu(root,tearoff=0)
  confmenu = Menu(root,tearoff=0)
  runmenu = Menu(root,tearoff = 0)
  runmenu.add_command(label = &quot;Open file from cmd&quot;, command = lambda:runfile())
  runmenu.add_separator()
  runner_command = StringVar()
  if isConf:
      for i in getConfs():
          runmenu.add_command(label = i, command = lambda:runnerConf(i))
      runmenu.add_separator()
  runmenu.add_command(label= &quot;New Runner&quot;,command = lambda:newrunner())
  toolsMenu.add_cascade(label = &quot;Runner&quot;, menu = runmenu)
  toolsMenu.add_command(label = &quot;Open cmd here&quot;, command = lambda:opencmd())
  Menubar.add_cascade(label=&quot;Tools&quot;,menu = toolsMenu)
  </code></pre>
  <pre><code>SPECS:
  OS: Windows 7 (i will upgrade to Windows 20 ONLY)
  Python: 3.8.10
  Arch: x86 (32 bit)
  </code></pre>