Tkinter – OptionMenu Widget
Prerequisite: Python GUI -tkinter
One of the most popular Python modules to build GUI(Graphical User Interface) based applications is the Tkinter module. It comes with a lot of functionalities like buttons, text-boxes, labels to be used in the GUI application, these are called widgets. In this article, we are going to learn what is the OptionMenu Widget and when it is used.
What is OptionMenu widget?
OptionMenu is basically a dropdown or popup menu that displays a group of objects on a click or keyboard event and lets the user select one option at a time.
- Import the Tkinter module.
- Create the default window
- Create a list of options to be shown at the dropdown/popup.
- Create a variable using.StringVar() method to keep track of the option selected in OptionMenu. Set a default value to it.
- Create the OptionMenu widget and pass the options_list and variable created to it.
Below is the implementation:
In the output GUI window, an OptionMenu widget is created it contains the default value of “Select an Option” as given. On click, it shows a dropdown containing the given options list.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course