📜  wxPython | Python中的GetToolByPos()函数

📅  最后修改于: 2022-05-13 01:55:14.045000             🧑  作者: Mango

wxPython | Python中的GetToolByPos()函数

在本文中,我们将了解 wxPython 的 wx.ToolBar 类中存在的 GetToolByPos()函数。 GetToolByPos()函数用于简单地返回指向特定位置的工具的指针。
GetToolByPos()函数采用一个参数,即 pos(工具的位置)。

代码示例 1:

wx.ToolBar.GetToolByPos(self, pos)

输出:

wx.ToolBarToolBase

代码示例 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(1)
  
        # print tool label
        print(obj.GetLabel())
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

输出:

Tooltwo