[Tkinter-discuss] optionmenu insert
Michael Lange
klappnase at web.de
Tue May 2 11:12:52 CEST 2006
On Mon, 01 May 2006 18:06:24 +0200
Pavel Kosina <geon at post.cz> wrote:
> Hi,
>
> I dont know how to dynamically add items to optionmenu.
> I found this
> http://aspn.activestate.com/ASPN/docs/ActiveTcl/iwidgets/optionmenu.n.html
> insert method, but it is not working or wrong done by me.
>
> w = OptionMenu(master, variable, *OPTIONS )
> w.insert(1,"something")
>
> Neither dir(w) nor print w.config() didnt help much.
>
Hi Pavel,
you can access the OptionMenu's Menu by its 'menu' key:
>>> from Tkinter import *
>>> root = Tk()
>>> s = StringVar()
>>> s.set('eggs')
>>> o = OptionMenu(root, s, 'eggs', 'spam', 'foo', 'bar')
>>> o.pack()
>>> o['menu'].insert('end', 'command', label='blah')
I hope this helps
Michael
More information about the Tkinter-discuss
mailing list