Open In App

wxPython – Remove() function in wx.MenuBar

Last Updated : 15 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we are going to learn about Remove() function of wx.MenuBar class. Remove() function removes Menu from a particular position in MenuBar in frame. This function takes pos parameter, that is, position of Menu to be deleted.

Parameters :

Parameter Input Type Description
pos int The position of the new menu in the menu bar

Code :
Let’s create a window with two menus in menubar Menu_one and Menu_two.

Python3




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(20, "two")
  
        menubar.Append(fm1, '&Menu_one')
        menubar.Append(fm2, '&Menu_two')
        self.SetMenuBar(menubar)
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
          
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()



Output :

Code:
Let’s write a code to remove Menu_two from menubar.

Python3




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(20, "two")
        menubar.Append(fm1, '&Menu_one')
        menubar.Append(fm2, '&Menu_two')
        self.SetMenuBar(menubar)
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
  
        # removing Menu_two from menubar
        menubar.Remove(1)
          
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output : 
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads