2

I have a quick question, how would you make a drop down menu in Tkinter like the one below:

enter image description here

This menu has a drop down option, how would you add a drop down in tkinter here is my code:

# Menu Bar 
MenuBar = Menu(root)
root.config(menu=MenuBar)
MenuBar.config(bg="White", fg="Black", activebackground="Whitesmoke", activeforeground="Black", activeborderwidth=1, font=('Monaco', 11))

# Settings Option
SettingsOption = Menu(MenuBar, tearoff=False)
MenuBar.add_cascade(label="Settings", menu=SettingsOption)
SettingsOption.add_command(label="Help", command=None)
SettingsOption.add_command(label="Documentation", command=None)

So whenever I click Settings I should get a menu called help. Then when I hover over help I should get another dropdown menu called documentation. How would you do this in Python Tkinter?

Skcoder
  • 299
  • 1
  • 9

1 Answers1

3

You can use add_cascade() to add sub-menu:

import tkinter as tk

root = tk.Tk()

menubar = tk.Menu(root)
menubar.config(bg="white", fg="black", activebackground="whitesmoke", activeforeground="black", activeborderwidth=1, font="Monaco 11")

settings_menu = tk.Menu(menubar, tearoff=False)

help_menu = tk.Menu(settings_menu, tearoff=False)
help_menu.add_command(label="Documentation")

settings_menu.add_cascade(label="Help", menu=help_menu)
menubar.add_cascade(label="Settings", menu=settings_menu)

root.config(menu=menubar)
root.mainloop()

enter image description here

acw1668
  • 40,144
  • 5
  • 22
  • 34
  • Is there a way to fix the drop down icon in documentation menu? I only want a drop down for the help menu not for the documentation option. How would you fix that? – Skcoder Feb 02 '21 at 23:22
  • Thanks so much, could you also help me with this if it is not to much to ask: https://stackoverflow.com/questions/66028969/how-do-you-place-a-drop-down-menu-above-a-non-drop-down-menu-in-tkinter. Thanks again! – Skcoder Feb 03 '21 at 14:42
  • This actually helped with my issue too thanks a ton. – ragethewolf Apr 03 '22 at 09:24