Here we are providing basic tutorial in Tkinter
on how to create a dropdown menu
in a Tkinter GUI application.
The following Tkinter code will demonstrate the same:
from tkinter import *
print("Ok Ok I wont")
root = Tk()
menu = Menu(root)
subMenu = Menu(menu)
subMenu.add_command(label="New Project...", command=doNothing)
editMenu = Menu(menu)
In the above code, we had defined a method called doNothing()
which prints something.
In the next few lines of code, we created a menu called menu
using the pre-defined method in Tkinter known as Menu
which takes root
window as a parameter.
Then we created two sub-menus called as subMenu
is used to add sub-menus by mentioning their names and labels.
is used to assign a particular command or a method to a particular option in a menu for example in above code,
an option New Project...
is assigned a method doNothing
which actually do nothing except printing some text.
is used to seperate options in a menu by having a geometrical line between them.
In the GUI application, we had created two sub-menus called as File
which are further having some options as shown below.