Open In App

Python – Enable function in wx.MenuBar

Last Updated : 10 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will learn about Enable() function in wx.MenuBar class of wxPython. Sometimes we want a menu item to get unclickable or clickable in that case we use Enable() function. Enable() function takes a boolean parameter, if it’s True then the item is clickable else it is greyed up and is unclickable.

Syntax :

wx.MenuBar.Enable(self, id, enable)

Parameters :

Parameter Input Type Description
id int The menu item identifier.
enable bool True to enable the item, False to disable it.

Code Example :




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
  
        self.InitUI()
  
    def InitUI(self):
        # create MenuBar using MenuBar() function
        menubar = wx.MenuBar()
        # add menu to MenuBar
        fileMenu = wx.Menu()
        # add submenu item
        fileItem = fileMenu.Append(20, 'SubMenu')
        menubar.Append(fileMenu, '&Menu# 1')
        self.SetMenuBar(menubar)
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
  
        # disable menu item using Enable() function
        menubar.Enable(20, False)
           
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads