Open In App

Python - FindItemById() function in wx.MenuBar

Last Updated : 10 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
In this article we are going to learn about FindItemById() object in wx.MenuBar class of wxPython. FindItemById() function returns a wx.MenuItem object tuple. It takes only one parameter that is id of menuitem of which wx.MenuItem object we need.
Syntax:
wx.MenuBar.FindItemById(self, id)
Parameters :
Parameter Input Type Description
id int Menu item identifier.
Return Type:
wx.MenuItem
Code 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')
        # get wx.MenuItem object
        menuitem = menubar.FindItemById(20)
        # print wx.MenuItem object tuple id = 20
        print(menuitem)
        # print label of menuitem
        print(menuitem.GetLabel())
         

def main():

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


if __name__ == '__main__':
    main()
Output :
<wx._core.MenuItem object at 0x7fe3009a5288&rt;
SubMenu

Practice Tags :

Similar Reads