tkinter menuitem question

Ken Guest kwg at renre-europe.com
Wed Mar 20 09:24:33 EST 2002


ok, I might be way off here but is there a way with a collection of
Tkinter menuitems that all have their callbacks set to be the one
function to determine which menuitem was clicked on?

for example, given the snippet:


        menubar1=Pmw.MenuBar(vbox1)
        menubar1.addmenu('TopLvlMenu','this is a tooltip')
        menubar1.addcascademenu('TopLvlMenu', 'Item#6','tool tip for
					item 6')
        menubar1.addmenuitem('Item#6', 'command', '',
		label="item#7",underline=0, command=menu_item_selected)
        menubar1.addmenuitem('Item#6', 'command', 'oct', label="item#8",
	        underline=0, command=menu_item_selected)
        menubar1.addmenuitem('TopLvlMenu', 'command', 'naoi',
		label="item#9", underline=0, command=menu_item_selected)
        menubar1.addmenuitem('TopLvlMenu', 'separator', '')
        menubar1.addmenuitem('TopLvlMenu', 'command', '',
		label="item10", underline=0, command=menu_item_selected)
        menubar1.pack(expand=NO, side=TOP)


Is it possible to give these menuitems the one handler function/callback
function that can determine which item was clicked on?
The reason for asking is that I have a dynamically generated cascading
popup menu and need to know which menuitem has been selected.

I have thought of displaying a very small dialog box which would only
contain a combobox and nothing else. the dialog box would be unloaded
once the user selects an item from the combobox but this wouldn't really
work as there need to be cascaded entries.

any ideas?

k.






More information about the Python-list mailing list