Python Tutorial

Step by Step Create Drop-Down Menus in Python Tkinter

How to Create Dropdown Menus With Tkinter in Python?

For creating a Dropdown menu, follow these steps:

1. Define the datatype of menu text, means integer, string, or any other datatype

2. Set initial menu text (That display initially)

3. Add menu value in option as a list

4. Create Dropdown menu

Below is an Implementation that creates Dropdown menus in Tkinter:

rt = Tk()

rt.geometry( "200x200" )

def show():

    label.config( text = clicked.get() )

options = [

    "Monday",

    "Tuesday",

    "Wednesday",

    "Thursday",

    "Friday",

    "Saturday",

    "Sunday"

]

ck = StringVar()

ck.set( "Monday" )

dp = OptionMenu( rt , clicked , *options )

dp.pack()

button = Button( rt , text = "click Me" , command = show ).pack()

label = Label( rt , text = " " )

label.pack()

rt.mainloop()

Did you find this article helpful?