Sunday, October 5, 2025
HomeLanguageswxPython | DeleteToolByPos() function in wx.ToolBar

wxPython | DeleteToolByPos() function in wx.ToolBar

In this article we are going to learn about DeleteToolByPos() function of wx.ToolBar class of wxPython. DeleteToolByPos() removes the specified tool from the toolbar and deletes it. Only difference between DeleteTool() and DeleteToolByPos() function is that DeleteToolByPos() specifies tool by its index.

Syntax : wx.toolbar.DeleteToolByPos(self, pos) 

Returns: True if the tool was deleted, False otherwise. 

Parameter :

Parameter Input Type Description
pos int position of tool starting from 0.

Example: 

Python3




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 DeleteToolByPos() function
        self.toolbar.DeleteToolByPos(0)
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output : On Starting Application : 

On button clicked: 

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

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6823 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS