Thursday, November 20, 2025
HomeLanguageswxPython – IsSubMenu() function in wx.MenuItem

wxPython – IsSubMenu() function in wx.MenuItem

In this article we are going to learn about IsSubMenu() function associated with wx.MenuItem class of wxPython. IsSubMenu() function simply returns True if the item is a submenu and False if the item is not a submenu.
No parameters are required by IsSubMenu() function.

Syntax:

wx.MenuItem.IsSubMenu(self)

Parameters:

No parameters are required by IsSubMenu() function.

Return Type:

bool

Code Example:




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')
        item = wx.MenuItem(fileMenu, 1, '&Check\tCtrl + c', helpString ="Check Help")
        item.SetSubMenu(sm)
        fileMenu.AppendMenu(wx.ID_ANY, 'I&mport', sm)
          
        n = item.IsSubMenu()
        # if item is sub menu
        if(n == True):
            print("Item is SubMenu Item")
        else:
            print("Item is not a SubMenu Item")
        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:

Item is SubMenu Item.

Output Window:

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
6779 POSTS0 COMMENTS
Nicole Veronica
11927 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6906 POSTS0 COMMENTS
Ted Musemwa
7163 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS