Skip to content
Related Articles

Related Articles

Improve Article
wxPython – SetLabel() function in wx.MenuBar
  • Last Updated : 11 May, 2020

Another important function in wx.MenuBar is SetLabel() function in wx.MenuBar class of wxPython. SetLabel() function is used to change the Label(title) of the menu item in menubar. It is used only after the menubar has been associated with a frame.

Syntax :

wx.MenuBar(self, id, label)

Parameters :

ParameterInput TypeDescription
idintMenu item identifier.
labelstringMenu item label.

Code Example :




import wx
  
  
class Example(wx.Frame):
        super(w).__init__(*args, **kwargs)
  
        # create MenuBar using MenuBar() function
        menubar = wx.MenuBar()
  
        # add menu to MenuBar
        fm1 = wx.Menu()
        fileitem = fm1.Append(20, "Item # 1")
        menubar.Append(fm1, '&Menu # 1')
        self.SetMenuBar(menubar)
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')  
   
        # change label of menu item to New Name
        menubar.SetLabel(20, "New Name")
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :