[Tkinter-discuss] Bind to event related to currently selected menu item

python at bdurham.com python at bdurham.com
Sat Nov 20 23:19:18 CET 2010


Kevin,

> Try <<MenuSelect>>.

Thanks for the recommendation. Any suggestions on how I can determine
the currently selected menu item in the event raised by <<MenuSelect>>?

# here's how I create my popup menu
popup = tk.Menu( menubar )
popup.bind( '<<MenuSelect>>', statusbarUpdate )

# here's the command I bind to
def statusbarUpdate( event=None ):
    for key in dir( event ):
        print key, getattr( event, key )

This outputs the following information as I move between menu items (eg.
the event is being raised properly).

Note: There seems to be no way to determine the current menu widget
(event.widget is a string vs. widget reference).

char ??
delta 0
height ??
keycode ??
keysym ??
keysym_num ??
num ??
send_event False
serial 238
state 0
time 1585806557
type 35
widget .#52754872.#52754872#52755392 <-- string vs. widget reference
width ??
x 36160384
x_root 487
y 53363120
y_root 307

Any suggestions appreciated!

Thank you,
Malcolm


> Wondering if there's a menu event I can bind to that's related to the
> currently selected menu item? By menu item I mean the items that show up
> in a popup menu like New, Open, Save, etc.
>
> Use case: I would like to update a statusbar area of our application
> with a description of the currently selected menu item.



More information about the Tkinter-discuss mailing list