在本文中,我們將學習wxPython的wx.ToolBar類的FindToolForPosition()函數。 FindToolForPosition()用於查找給定鼠標位置的工具。它占據窗口的x和y位置。
用法:
wx.ToolBar.FindToolForPosition(self, x, y)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
x | int | X位置。 |
y | int | Y位置。 |
Return Type:
wx.ToolBarToolBase
代碼示例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()
# 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 o tool
print(self.toolbar.FindToolForPosition(5, 5))
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
輸出:
<wx._core.ToolBarToolBase object at 0x0000009B92B041F0>
代碼示例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()
# Add Tools Using AddTool function
rtool = self.toolbar.AddTool(13, 'twoTool', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool2")
stool = self.toolbar.AddTool(14, 'twoTool', wx.Bitmap('user.png'), shortHelp ="Simple Tool2")
self.toolbar.Realize()
self.SetSize((350, 250))
self.SetTitle('Control')
self.Centre()
# print wx.ToolBarToolBase object o tool
print(self.toolbar.FindToolForPosition(40, 5).GetLabel())
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
輸出:
twoTool
相關用法
- wxPython FindControl()用法及代碼示例
- wxPython GetClassDefaultAttributes()用法及代碼示例
- wxPython GetToolBitmapSize()用法及代碼示例
- wxPython GetMargins()用法及代碼示例
- wxPython GetToolByPos()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython | FindToolForPosition() function in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。