Thursday, December 18, 2025
HomeLanguageswxPython | GetToolPos() function in python

wxPython | GetToolPos() function in python

In this article we are going to learn about GetToolPos() function associated with wx.ToolBar class of wxPython. GetToolPos() function simply returns the tool position in the toolbar, or NOT_FOUND if the tool is not found. GetToolPos() function only takes toolId(ID of the tool in question, as passed to AddTool) in the arguments.
 

Syntax: 

wx.ToolBar.GetToolPos(self, toolId)

Parameters :

Parameter Input Type Description
toolId int ID of the tool in question, as passed to AddTool.

Return: 
Returns the position of tool in toolbar starting from 0.
Return Type 

int

Code Example 1: 
 

Python3




import wx
 
 
class Example(wx.Frame):
    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 AddLabelTool function
        rtool = self.toolbar.AddLabelTool(id = 13, label = "Tool one", bitmap = wx.Bitmap('right.png'), shortHelp ="short help 1", longHelp = "Long help associated with simple tool 1")
        stool = self.toolbar.AddLabelTool(id = 14, label = "Tool two", bitmap = wx.Bitmap('wrong.png'), shortHelp ="short help 2", longHelp = "Long help associated with simple tool 2")
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
        # variable bl storing position of tool
        bl = self.toolbar.GetToolPos(14)
 
        # print tool position value
        print(bl)
 
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output : 
 

1

Code Example 2: 
 

Python3




import wx
 
 
class Example(wx.Frame):
    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 AddLabelTool function
        rtool = self.toolbar.AddLabelTool(id = 13, label = "Tool one", bitmap = wx.Bitmap('right.png'), shortHelp ="short help 1", longHelp = "Long help associated with simple tool 1")
        stool = self.toolbar.AddLabelTool(id = 14, label = "Tool two", bitmap = wx.Bitmap('wrong.png'), shortHelp ="short help 2", longHelp = "Long help associated with simple tool 2")
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
        # variable bl storing position of tool
        bl = self.toolbar.GetToolPos(13)
 
        # print tool position value
        print(bl)
 
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output : 
 

0

 

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

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11957 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12034 POSTS0 COMMENTS
Shaida Kate Naidoo
6957 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6909 POSTS0 COMMENTS
Umr Jansen
6888 POSTS0 COMMENTS