Thursday, September 25, 2025
HomeLanguageswxPython – Enable() function in wx.MenuItem

wxPython – Enable() function in wx.MenuItem

In this article we are going to learn about Enable() function associated with the wx.MenuItem class of wxPython. As the name Enable suggests Enable() function enables or disables the menu item.
It only takes a boolean parameter enable, True for Enable and False for Disable.

Syntax: wx.MenuItem.Enable(self, enable=True)

Parameters:

Parameter Input Type Description
enable bool True for Enable and False for Disable.
Code Example:




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
  
        self.InitUI()
  
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
  
        self.menubar = wx.MenuBar()
        self.fileMenu = wx.Menu()
        self.item = wx.MenuItem(self.fileMenu, 1, '&Check')
        self.fileMenu.Append(self.item)
  
        # Disable menu item using Enable() function
        self.item.Enable(enable = False)
        self.menubar.Append(self.fileMenu, '&File')
        self.SetMenuBar(self.menubar)
  
        self.SetSize((350, 250))
        self.SetTitle('Icons and shortcuts')
        self.Centre()
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output:

Last Updated :
04 Jun, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6754 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS