Open In App

wxPython | FindToolForPosition() function in python

Last Updated : 02 Mar, 2023
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

In this article we are going to learn about FindToolForPosition() function of class wx.ToolBar of wxPython. FindToolForPosition() is used to find a tool for the given mouse position. It takes x and y position of the window.

Syntax:

wx.ToolBar.FindToolForPosition(self, x, y)

Parameters :

ParameterInput TypeDescription
xintX position.
yintY position.

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.FindToolForPosition(5, 5))


def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()

Output :

<wx._core.ToolBarToolBase object at 0x0000009B92B041F0>

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, 'twoTool', wx.Bitmap('wrong.png'), shortHelp =&quot;Simple Tool2&quot;)
        stool = self.toolbar.AddTool(14, 'twoTool', wx.Bitmap('user.png'), shortHelp =&quot;Simple Tool2&quot;)
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()

        # print wx.ToolBarToolBase object of tool
        print(self.toolbar.FindToolForPosition(40, 5).GetLabel())


def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()

Output:

twoTool

Article Tags :
Practice Tags :

Similar Reads