Navigation is the most important part of any application, as it improves the user experience in an aesthetic way. Using Tkinter, we can create menus and submenus very efficiently.
Tkinter has an inbuilt function to create menus and these can be invoked with another tkinter widget or window. Tkinter.Menu module provides some properties in Menu-items. Some of these properties are used to label the buttons, toggling the button, adding submenus using cascade properties, etc.
In this article, we will see how to create a dropdown menu using tkinter.Menu and its Menu-item properties. We will use OptionMenu widget to create a list of options and related commands.
from tkinter import * win =Tk() win.geometry("700x300") label= Label(win, text= "Select any One Language!", font= ("", 10)) label.pack(pady=30) #Access the Menu Widget using StringVar function clicked= StringVar() #Create an instance of Menu in the frame main_menu = OptionMenu(win, clicked, "C++", "Java", "Python", "Rust","Go","Ruby") main_menu.pack() win.mainloop()
Running the above code will create a dropdown Menu.