Python – Enable function in wx.MenuBar
Last Updated :
10 May, 2020
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 ):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
fileItem = fileMenu.Append( 20 , 'SubMenu' )
menubar.Append(fileMenu, '&Menu# 1' )
self .SetMenuBar(menubar)
self .SetSize(( 300 , 200 ))
self .SetTitle( 'Menu Bar' )
menubar.Enable( 20 , False )
def main():
app = wx.App()
ex = Example( None )
ex.Show()
app.MainLoop()
if __name__ = = '__main__' :
main()
|
Output:
Share your thoughts in the comments
Please Login to comment...