[wxPython-users] Can't get menu title for popup menus in Windows

Robin Dunn robin at alldunn.com
Fri Feb 2 11:48:47 PST 2007


Chris Mellon wrote:
> On 2/2/07, Isaac Wagner <geekyisaac at gmail.com> wrote:

>> On Linux things work as expected.  For title I get either "Menu1" or
>> "Menu2" depending on which submenu the item was selected from.
>> However, on Windows the title is always an empty string.  Is this a wx
>> issue or is it a Windows issue?  Does anyone know any workarounds?
>>
> 
> I've never tried this, although I suspect it's a Windows artifact that
> wx should probably try to work around. The reason why I've never tried
> it, though, is that I bind the submenus to different event handlers by
> using different IDs instead of doing secondary dispatch. You might try
> taking that approach.

On Windows event.GetEventObject is returning the parent menu, not the 
submenu.  It looks like it is just due to the way that menus are sent in 
Windows.  The command event comes to the window and wx just checks if it 
was due to there being a popup menu active and if so it sets the popup 
as the event object.

A workaround would be to use the event ID to get the wx.MenuItem, then 
you can use GetMenu to find the (sub)menu it belongs to.  But Chris's 
suggestion of binding the events directly to their handlers as you 
create the items is the better way to solve this problem.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list