Open In App

Python - FindItem() function in wx.MenuBar

Last Updated : 10 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
In this article we will learn about FindItem function present in wx.MenuBar class of wxPython. FindItem() only takes one parameter that is item identifier. FindItem() finds the menu item object associated with the given menu item identifier.
Syntax :
wx.MenuBar.FindItem(self, id)
Parameters :
Parameter Input Type Description
id int Menu item identifier.
Example: Python3 1==
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')
        print(menubar.FindItem(20))
         

def main():

    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()
Output :
(<wx._core.MenuItem object at 0x7fd6797401f8&rt;, <wx._core.Menu object at 0x7fd67973d828&rt;)

Practice Tags :

Similar Reads