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 :
Parameter Input Type Description pos int position 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