Friday, November 21, 2025
HomeLanguageswxPython – GetSubMenu() function in wx.MenuItem

wxPython – GetSubMenu() function in wx.MenuItem

In this article we are going to learn about GetSubMenu() function associated with the class wx.MenuItem in wxPython. GetSubMenu() function returns the submenu associated with the menu item, or None if there isn’t one. No arguments are needed in GetSubMenu() function.

Syntax:

wx.MenuItem.GetSubMenu(self)

Parameters:

No parameters are needed in GetSubMenu() function.

Return Type:

wx.Menu

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):
 
        menubar = wx.MenuBar()
 
        fileMenu = wx.Menu()
 
        sm = wx.Menu()
        sm.Append(wx.ID_ANY, 'Submenu item 1')
        sm.Append(wx.ID_ANY, 'Submenu item 2')
        sm.Append(wx.ID_ANY, 'Submenu item 3')
        self.st = wx.StaticText(self, label ="", pos =(20, 20), style = wx.ALIGN_LEFT)
        item = wx.MenuItem(fileMenu, 1, '&Check\tCtrl + c', helpString ="Check Help")
        item.SetSubMenu(sm)
        fileMenu.AppendMenu(wx.ID_ANY, 'I&mport', sm)
        # get submenu
        s = item.GetSubMenu()
        # get total sub menu item
        n = s.MenuItemCount
        # print total sub menu item
        print(n)
        self.st.SetLabel(str(n)+" total submenu items")
        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)
 
        self.SetSize((350, 250))
        self.SetTitle('Submenu')
        self.Centre()
 
 
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output:

3

Output:

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

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS