Skip to content
Related Articles

Related Articles

wxPython – FindMenuItem() function in wx.MenuBar

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 16 Jun, 2021

In this article we will learn about FindMenuItem() function present in wx.MenuBar class of wxPython. FindMenuItem() is used to return item identifier. FindMenuItem() takes two parameters that is Menu title and submenu item string.
 

Syntax : 
 

wx.MenuBar.FindMenuItem(self, menuString, itemString)

Parameters : 

 

ParameterInput TypeDescription
menuStringstringMenu title to find.
itemStringstringItem to find.

Return: FindMenuItem() returns the menu item identifier, or wx.NOT_FOUND if none was found. 
 

Code Example: 
 

Python3




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
        fm1 = wx.Menu()
        fileitem = fm1.Append(20, "Item # 1")
        menubar.Append(fm1, '&Menu # 1')
        self.SetMenuBar(menubar)
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
 
        # get id identifier of submenu item
        id = menubar.FindMenuItem("&Menu # 1", "Item # 1")
        print(id)   
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()

Output: 
 

CommandLine Output : 
 

20

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!