Tuesday, November 26, 2024
Google search engine
HomeLanguagesPython – FindItemById() function in wx.MenuBar

Python – FindItemById() function in wx.MenuBar

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 :




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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments