tkinter dropdown
Python hosting: Host, run, and code Python in the cloud!
Tkinter supports dropdown menus. This is similar to your standard combobox on your operating system.
The widget is called OptionMenu and the parameters you need are: frame, tk variable and a dictionary with choices.
Related course:
Tkinter dropdown example
The example below creates a Tkinter window with a combobox. Code to create a simple Tkinter menu with a dropdown list:
|
It starts by creating a Tk object and pass it to a tkinter frame created with Frame()
|
A grid is added to the frame which will hold the combo-box.
|
The popup menu contains a list of options which is defined in the variable choices.
A Tkinter variable is created with the line:
|
The default value of the variable is set with the .set() method.
We create the Tkinter combobox with:
|
And link the callback method change_dropdown to this combobox.
If you are new to programming Tkinter, I highly recommend this course.
Leave a Reply: