📌  相关文章
📜  wxPython | wx.ToolBar 中的 DeleteToolByPos()函数

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

wxPython | wx.ToolBar 中的 DeleteToolByPos()函数

在本文中,我们将了解 wxPython 的 wx.ToolBar 类的 DeleteToolByPos()函数。 DeleteToolByPos() 从工具栏中删除指定的工具并将其删除。 DeleteTool() 和 DeleteToolByPos()函数之间的唯一区别是 DeleteToolByPos() 通过其索引指定工具。

例子:

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):
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        self.ptool = self.toolbar.AddTool(12,
                                          'oneTool',
                                          wx.Bitmap('path / wxPython / right.png'),
                                          shortHelp ="Simple Tool")
          
        self.ptool = self.toolbar.AddTool(13,
                                          'oneTool',
                                          wx.Bitmap('path / wxPython / wrong.png'),
                                          shortHelp ="Simple Tool")
          
        self.btn = wx.Button(pnl,
                             label ='Delete',
                             pos =(20, 20))
  
        self.btn.Bind(wx.EVT_BUTTON, self.Onclick)
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
  
    def Onclick(self, e):
        # delete tool using DeleteTool() function
        self.toolbar.DeleteToolByPos(0)
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

输出 :
在开始申请时:

点击按钮: