Thursday, November 28, 2024
Google search engine
HomeLanguageswxPython – GetMenuCount() function in wx.MenuBar

wxPython – GetMenuCount() function in wx.MenuBar

GetMenuCount() function is another function present in wx.MenuBar class of wxPython. GetMenuCount() function return total number of menus present in MenuBar. It takes no arguments.

Syntax: wx.MenuBar.GetMenuCount(self)

Parameters : No parameters in GetMenuItem()

Return : Returns the number of menus in this menubar.

Code :

Set label of statictext as total number of menu items.




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kw):
        super(Example, self).__init__(*args, **kw)
  
        # create MenuBar using MenuBar() function
        menubar = wx.MenuBar()
  
        # add menu to MenuBar
        fm1 = wx.Menu()
        fileitem = fm1.Append(20, "one")
  
        fm2 = wx.Menu()
        fileitem2 = fm2.Append(21, "two")
        menubar.Append(fm1, '&Menu_one')
        menubar.Append(fm2, '&Menu_two')
        self.SetMenuBar(menubar)
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
        st1 = wx.StaticText(self, label ="Total Menus :" + str(menubar.GetMenuCount()), 
                                                                 style = wx.ALIGN_LEFT)
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output :

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