在本文中,我們將學習與wxPython的wx.ToolBar類關聯的GetToolPos()函數。 GetToolPos()函數僅返回工具在工具欄中的位置,如果未找到工具,則返回NOT_FOUND。 GetToolPos()函數僅在參數中接受tooId(相關工具的ID,傳遞給AddTool)。
用法:
wx.ToolBar.GetToolPos(self, toolId)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
toolId | int | 有問題的工具的ID,傳遞給AddTool。 |
返回:
從0開始返回工具在工具欄中的位置。
返回類型
int
代碼示例1:
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 AddTool 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()
輸出:
1
代碼示例2:
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 AddTool 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()
輸出:
0
相關用法
- wxPython FindToolForPosition()用法及代碼示例
- wxPython FindControl()用法及代碼示例
- wxPython GetClassDefaultAttributes()用法及代碼示例
- wxPython GetToolBitmapSize()用法及代碼示例
- wxPython GetMargins()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython | GetToolPos() function in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。