[Tutor] Dynamically populate Tkinter OptionMenu with list

jfouhy@paradise.net.nz jfouhy at paradise.net.nz
Thu Jul 21 00:19:09 CEST 2005


Quoting Bernard Lebel <3dbernard at gmail.com>:

> I have this problem. I build a list of elements, and I never know in
> advance how many or what will be the elements.
> 
> I then wish to populate an OptionMenu with this list of elements.

Do you know the list of elements before you create the option menu?

If so, you can do something like this:

# suppose aElements is the list of elements, and var1 is a StringVar.
oOption = OptionMenu(oRoot, var1, aElements[0], *aElements[1:])

If you want to create the OptionMenu first, and then later set the list of
elements ... then it is a bit more difficult.

-- 
John.


More information about the Tutor mailing list