Search code examples
pythonwxpythonwxwidgets

wxPython - Disable a whole menu


I have come across a problem while using wxPython lately: I want to grey out a whole wx.Menu and I can't find a way to do it. I could disable all the wx.MenuItem instances related to the wx.Menu, but I find it less efficient ergonomically speaking than greying out the menu itself.

The wx.Menu class has a method named Enable() which accepts the 'enable' argument, but its solely use is to enable/disable a related wx.MenuItem and not the wx.Menu itself. Actually, I'm not even sure that what I want can be done.

However, I would be glad to listen to your solutions if you have some.


Solution

  • Enable is just for the menu items. EnableTop should counter-intuitively disable the entire menu. See my old tutorial on menus about half-way down for more info. Here's how I did it:

    self.menuBar.EnableTop(0, False)
    

    Note that it's zero-based, so zero is the first menu, one is the second, etc.