Friday, October 3, 2025
HomeLanguageswxPython| FindById() function in python

wxPython| FindById() function in python

In this article we are going to learn a simple function that is FindById() in wx.ToolBar class of wxPython. FindById is a simple function and returns a pointer to the tool identified by id or None if no corresponding tool is found. FindById() takes only single parameter that is id of a particular tool.

Syntax :

wx.ToolBar.FindById(self, id)

Parameters :

Parameter Input Type Description
toolid int An integer by which the tool may be identified in subsequent operations.

Returns : Return pointer to corresponding tool. Return Type:

wx.ToolBarToolBase

Code Example 1: 

Python3




import wx
 
 
class Example(wx.Frame):
    global count
    count = 0;
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'twoTool', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool2")
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
 
        # print wx.ToolBarToolBase object of tool
        print(self.toolbar.FindById(13))
 
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output :

<wx._core.ToolBarToolBase object at 0x0000003D2DB241F0>

Code Example 2: 

Python3




import wx
 
 
class Example(wx.Frame):
    global count
    count = 0;
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'oneTool', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool1")
        stool = self.toolbar.AddTool(14, 'twoTool', wx.Bitmap('user.png'), shortHelp ="Simple Tool2")
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
 
        # print label string
        print(self.toolbar.FindById(14).GetLabel())
 
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output :

twoTool
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS