Skip to content
Related Articles

Related Articles

Improve Article

wxPython – GetLabel() function in wx.MenuBar

  • Last Updated : 11 May, 2020

GetLabel() is another function present in wx.MenuBar class of wxPython. GetLabel() function is used to return the label of menu inside menu present in menubar. GetLabel() function only takes id as an argument and returns string Label of menu item.

Syntax :

wx.MenuBar.GetLabel(self, id)

Parameters :

ParameterInput TypeDescription
idintThe menu item identifier.

Returns : The menu item label, or the empty string if the item was not found.

Code Example :

Lets return labels of menu item present in Menu_one and Menu_two Menus in menubar.

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(21, "two")
        menubar.Append(fm1, '&Menu_one')
        menubar.Append(fm2, '&Menu_two')
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
        pnl = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)
        font = wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.DEFAULT)
        st1 = wx.StaticText(pnl, label = menubar.GetLabel(20), style = wx.ALIGN_LEFT)
        st2 = wx.StaticText(pnl, label = menubar.GetLabel(21), style = wx.ALIGN_LEFT)
        vbox.Add(st1, flag = wx.ALL, border = 15)
        vbox.Add(st2, flag = wx.ALL, border = 15)
def main():
    app = wx.App()
    ex = Example(None)

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 :