当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


wxPython GetToolPos()用法及代码示例


在本文中,我们将学习与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




相关用法


注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython | GetToolPos() function in python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。