Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

wxPython | GetToolByPos() function in python

  • Last Updated : 18 Aug, 2020

In this article we are going to learn about GetToolByPos() function present in wx.ToolBar class of wxPython. GetToolByPos() function is used to simply return a pointer to the tool at specific position.
GetToolByPos() function takes a single parameter that is pos(position of tool).

Syntax:

wx.ToolBar.GetToolByPos(self, pos)

Parameters :

ParameterInput TypeDescription
posintposition of tool starting from 0.

Return Type:

wx.ToolBarToolBase

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):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        self.toolbar.SetMargins(10, 10)
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'Toolone', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool2")
        stool = self.toolbar.AddTool(14, 'Tooltwo', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
  
        obj = self.toolbar.GetToolByPos(1)
  
        # print tool label
        print(obj.GetLabel())
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

Output:

Tooltwo

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):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        self.toolbar.SetMargins(10, 10)
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'Toolone', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool2")
        stool = self.toolbar.AddTool(14, 'Tooltwo', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
  
        obj = self.toolbar.GetToolByPos(0)
  
        # print tool label
        print(obj.GetLabel())
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

Output:

Toolone

 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 :

Start Your Coding Journey Now!