📜  wxPython | Python中的GetToolPos()函数

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

wxPython | Python中的GetToolPos()函数

在本文中,我们将学习与 wxPython 的 wx.ToolBar 类关联的 GetToolPos()函数。 GetToolPos()函数仅返回工具栏中的工具位置,如果未找到工具,则返回 NOT_FOUND。 GetToolPos()函数仅在参数中采用 tooId(相关工具的 ID,如传递给 AddTool)。

代码示例 1:

Python3
wx.ToolBar.GetToolPos(self, toolId)


Python3
int


输出 :

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()

代码示例 2:

Python3

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()

输出 :

1