Open In App

wxPython – Insert() function in wx.MenuBar

Last Updated : 10 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we are going to learn about Insert() function associated to wx.MenuBar class of wxPython. So Insert() function is a very important function in wx.MenuBar class. Insert() function Inserts the menu at the given position into the menu bar.

Inserting menu at position 0 will insert it in the very beginning of it, inserting at position GetMenuCount is the same as calling Append .

Syntax: wx.MenuBar.Insert(self, pos, menu, title)

Parameters:

Parameter Input Type Description
pos int The position of the new menu in the menu bar
menu wx.Menu The menu to add. wx.MenuBar owns the menu and will free it.
title string The title of the menu.

Code Example:




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
  
        self.InitUI()
  
    def InitUI(self):
  
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.menubar = wx.MenuBar()
        self.fileMenu = wx.Menu()
        self.fileMenu2 = wx.Menu()
        self.item = wx.MenuItem(self.fileMenu, 1, '&Check',
                                 helpString ="Check Help")
        self.item.SetBitmap(wx.Bitmap('right.png'))
        self.fileMenu.Append(self.item)
        self.menubar.Append(self.fileMenu, '&File')
  
        # INSERT A NEW MENU IN MENUBAR AT POSITION 0
        self.menubar.Insert(0, self.fileMenu2, '&New Menu')
        self.SetMenuBar(self.menubar)
        self.SetSize((350, 250))
        self.SetTitle('New Frame Title')
        self.Centre()
  
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