Sunday, March 1, 2026
HomeLanguageswxPython – ClearTools() function in wx.Toolbar

wxPython – ClearTools() function in wx.Toolbar

Another function in wxPython Series we are going to learn is ClearTools() function in wx.ToolBar class of wxPython. ClearTools() is a very basic function of wx.ToolBar. ClearTools() function deletes all the tools in the toolbar.

Syntax : wx.ToolBar.CLearTools(self)

Return Type: wx.ToolBarToolBase

Code Example To create Toolbar:




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()
        ptool = self.toolbar.AddTool(12, 'oneTool',  wx.Bitmap('/home/wxPython/right.png'), shortHelp ="Simple Tool")
        qtool = self.toolbar.AddTool(12, 'oneTool',  wx.Bitmap('/home/wxPython/right.png'),  shortHelp ="Simple Tool")
        rtool = self.toolbar.AddTool(12, 'oneTool',  wx.Bitmap('/home/wxPython/right.png'),  shortHelp ="Simple Tool")
        self.btn = wx.Button(pnl, label ='Clear Tools', 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):
        # clear tools using ClearTools() function
        self.toolbar.ClearTools()
        self.btn.SetLabel("Cleared")
          
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output :
On starting window:

On clicking button:

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

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS