Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

wxPython | FindControl() function in Python

  • Last Updated : 04 Jun, 2020

In this particular article we are going to learn about FindControl() article of wx.ToolBar class of wxPython. FindControl() function is used to returns a pointer to the control identified by id or None if no corresponding control is found. It takes only one parameter ‘id’.

Syntax :

wx.ToolBar.FindControl(self, id)

Parameters :

ParameterInput TypeDescription
idintIdentifier for control.

Returns Type:

wx.Control

Code Example 1:




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):
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        ctrl = wx.Control(self.toolbar, 21, wx.DefaultPosition, wx.DefaultSize, style = 0, name ='control')
        # Add control using AddControl() method
        rtool = self.toolbar.AddControl(ctrl, 'control')
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Simple toolbar')
        self.Centre()
  
        print(self.toolbar.FindControl(21))
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

Output :

<wx._core.Control object at 0x00000026931240D0>

Code Example 2:




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):
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        ctrl = wx.Control(self.toolbar, 21, wx.DefaultPosition, wx.DefaultSize, style = 0, name ='control')
        # Add control using AddControl() method
        rtool = self.toolbar.AddControl(ctrl, 'control')
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Simple toolbar')
        self.Centre()
  
        print(self.toolbar.FindControl(21).GetName())
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

Output :

control


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!