Friday, November 14, 2025
HomeLanguageswxPython | RemoveTool() function in wx.ToolBar

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




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)
        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()
 
    def OnOne(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()
 
    def OnQuit(self, e):
        self.Close()
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output: before clicking cross tool: after clicking cross tool:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS