Python – FindItemById() function in wx.MenuBar
Last Updated :
10 May, 2020
In this article we are going to learn about FindItemById() object in wx.MenuBar class of wxPython. FindItemById() function returns a wx.MenuItem object tuple. It takes only one parameter that is id of menuitem of which wx.MenuItem object we need.
Syntax:
wx.MenuBar.FindItemById(self, id)
Parameters :
Parameter |
Input Type |
Description |
id |
int |
Menu item identifier. |
Return Type:
wx.MenuItem
Code Example :
import wx
class Example(wx.Frame):
def __init__( self , * args, * * kwargs):
super (Example, self ).__init__( * args, * * kwargs)
self .InitUI()
def InitUI( self ):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
fileItem = fileMenu.Append( 20 , 'SubMenu' )
menubar.Append(fileMenu, '&Menu# 1' )
self .SetMenuBar(menubar)
self .SetSize(( 300 , 200 ))
self .SetTitle( 'Menu Bar' )
menuitem = menubar.FindItemById( 20 )
print (menuitem)
print (menuitem.GetLabel())
def main():
app = wx.App()
ex = Example( None )
ex.Show()
app.MainLoop()
if __name__ = = '__main__' :
main()
|
Output :
<wx._core.MenuItem object at 0x7fe3009a5288&rt;
SubMenu
Share your thoughts in the comments
Please Login to comment...