Related Articles

Related Articles

wxPython – Remove() function in wx.MenuBar
  • Last Updated : 15 May, 2020

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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()

chevron_right



Output :

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

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

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()

chevron_right


Output : 
 


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :