Friday, October 10, 2025
HomeLanguageswxPython – EnableTool() function in wx.Toolbar

wxPython – EnableTool() function in wx.Toolbar

In this article we are going to learn EnableTool() function of class wx.ToolBar of wxPython. EnableTool is used to enable or disable(make clickable and unclickable) the tool present in toolbar.

Syntax :

wx.ToolBar.EnableTool(self, toolid, enable)

Parameters :

Parameter Input Type Description
toolid int ID of the tool to enable or disable, as passed to AddTool .
enable bool If True, enables the tool, otherwise disables it.

Code Example: 

Python3




import wx
 
 
class Example(wx.Frame):
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        qtool = self.toolbar.AddTool(12, 'Quit', wx.Bitmap('/Desktop/wxPython/signs.png'))
        self.toolbar.Realize()
 
        self.Bind(wx.EVT_TOOL, self.OnQuit, qtool)
 
        self.SetSize((350, 250))
        self.SetTitle('Simple toolbar')
        self.Centre()
        self.btn = wx.Button(pnl, label ='Disable', pos =(20, 20))
 
        self.btn.Bind(wx.EVT_BUTTON, self.Onclick)
 
        self.SetSize((350, 250))
        self.SetTitle('wx.Button')
        self.Centre()
 
 
    def OnQuit(self, e):
        self.Close()
 
    def Onclick(self, e):
        # disable tool using EnableTool
        self.toolbar.EnableTool(12, False)
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output :

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

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS