tkinter optionmenu code example

Example 1: dropdown in tkinter

from Tkinter import *

master = Tk()

variable = StringVar(master)
variable.set("one") # default value

w = OptionMenu(master, variable, "one", "two", "three")
w.pack()

mainloop()

Example 2: python optionmenu tkinter

from tkinter import Tk, StringVar, OptionMenu, mainloop
parent = Tk()
varList = StringVar(parent)
varList.set("Red")
om = OptionMenu(parent, varList, "Yellow", "Pink", "RED", "Brown", "Black", "Blue")
om.pack()
parent.mainloop()