wxPython | RemoveTool() function in wx.ToolBar

In this article we are going to learn about RemoveTool() function associated with wx.ToolBar class of wxPython. RemoveTool() removes the given tool from the toolbar but doesn’t delete it. This allows inserting/adding this tool back to this (or another) toolbar later. RemoveTool() takes only id as parameter.
Syntax:
wx.ToolBar.RemoveTool(self, id)Parameters :
Parameter Input Type Description id int ID of the tool in question, as passed to AddTool . Return Type:
wx.ToolBarToolBase
Code Example 1:
Python3
| importwxclassExample(wx.Frame):    def__init__(self, *args, **kwargs):        super(Example, self).__init__(*args, **kwargs)        self.InitUI()    defInitUI(self):        self.locale =wx.Locale(wx.LANGUAGE_ENGLISH)        self.toolbar =self.CreateToolBar()        td =self.toolbar.AddTool(1, '', wx.Bitmap('wrong.png'))        te =self.toolbar.AddTool(2, '', wx.Bitmap('right.png'))        tf =self.toolbar.AddTool(3, '', wx.Bitmap('sep.png'))        self.toolbar.Realize()        self.Bind(wx.EVT_TOOL, self.OnOne, td)        self.SetSize((350, 250))        self.SetTitle('Undo redo')        self.Centre()    defOnOne(self, e):        # delete tools from toolbar using RemoveTool() function        self.toolbar.RemoveTool(id=2)        self.toolbar.RemoveTool(id=3)        # Realize() called to finalize new added tools        self.toolbar.Realize()    defOnQuit(self, e):        self.Close()defmain():    app =wx.App()    ex =Example(None)    ex.Show()    app.MainLoop()if__name__ =='__main__':    main() | 
Output: before clicking cross tool: 
 
				 
					


