[wxPython-dev] MenuItem problem on Windows wxPython 2.8

Paul McNett p at ulmcnett.com
Fri Jan 12 15:51:08 PST 2007


Robin Dunn wrote:
> If no label is given then it assumes that you are wanting to use a stock 
> label and so it calls wxGetStockLabel to look it up, which is basically 
> just a big switch statement that maps IDs to strings.  If the given ID 
> is not in there then it does the assert.  These work for me:
> 
>  >>> import wx
>  >>> menu = wx.Menu()
>  >>> mi = wx.MenuItem(menu, wx.ID_EXIT)
>  >>> mi = wx.MenuItem(menu, -1, "Hello")
>  >>> mi = wx.MenuItem(menu, wx.ID_EXIT, "Goodbye")
>  >>> mi = wx.MenuItem(menu, wx.NewId(), "Foo")
> 
> These will fail:
> 
>  >>> mi = wx.MenuItem(menu, wx.ID_DEFAULT)
>  >>> mi = wx.MenuItem(menu, -1)
>  >>> mi = wx.MenuItem(menu, wx.NewId())

Thanks Robin, I finally got it worked out. Dabo noticed previously on 
Windows that in order to change the Caption of a menu item, we first had 
to SetText("") or the new Caption wouldn't display correctly, so only on 
Windows were we running SetText("") before calling 
SetText(real_caption). So I changed it to SetText(" ") which works 
without trouble.

I'm sure noone else ever calls SetText() on menu items once created 
(they probably just create new menu items and delete the old), so we 
were the only ones that noticed it.

-- 
pkm ~ http://paulmcnett.com





More information about the wxpython-dev mailing list