wxPython – Add Sub-Menu in menubar

In this article we will learn how can we add submenu item to menu item present on menubar. We can do this by same Append() function present in wxMenuBar class.
 
Syntax: wx.MenuBar.Append(self, menu, title)
Parameters:
Parameter Input Type Description menu wx.Menu The menu to add. Do not deallocate this menu after calling Append . title string The title of the menu, must be non-empty. Return: bool
Code Example: 
 
Python3
| importwxclassExample(wx.Frame):    def__init__(self, *args, **kwargs):        super(Example, self).__init__(*args, **kwargs)        self.InitUI()    defInitUI(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')defmain():    app =wx.App()    ex =Example(None)    ex.Show()    app.MainLoop()if__name__ =='__main__':    main() | 
Output :
 
 
				 
					



