[Tkinter-discuss] How to set optionmenu without setting the variable

david.giesen at kodak.com david.giesen at kodak.com
Wed Nov 4 20:44:10 CET 2009

Well - now I can say I learned something today!

Your method also demonstrates how to add additional items after creation 
without using the Tkinter private routine _setit, which is also nice.


David J. Giesen | Research Scientist | FPEG US Display OLED Materials R+D 
Eastman Kodak Company | 2/83/KRL MC02216 | Rochester, NY 14650 | 
david.giesen at kodak.com | 1-585-588-0480 Office | 

Michael Lange <klappnase at web.de>
tkinter-discuss at python.org
11/04/2009 02:30 PM
Re: [Tkinter-discuss] How to set optionmenu without setting the variable
Sent by:
tkinter-discuss-bounces+david.giesen=kodak.com at python.org


On Wed, 4 Nov 2009 08:23:39 -0500
david.giesen at kodak.com wrote:

> I don't believe there is any way to create an OptionMenu without
> using a Tk variable.

Actually you can:


from Tkinter import *

root = Tk()
om = OptionMenu(root, None, '1', '2')
om.pack(padx=100, pady=100)

items = ('a', 'b', 'c', 'd')
def callback(item):
    print 'selected:', item

om['menu'].delete(0, 'end')
for x in items:
    om['menu'].add_command(label=x, command=lambda item=x: callback(item))



I needed this once, because I was not able to handle unicode filenames
properly using a Tk textvariable, so you see it looks overly
complicated but in some cases may have its use.

I hope this helps


Tkinter-discuss mailing list
Tkinter-discuss at python.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20091104/6e4ee3d9/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 826 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20091104/6e4ee3d9/attachment-0001.gif>

More information about the Tkinter-discuss mailing list