Skip to content
Related Articles

Related Articles

wxPython – EnableTool() function in wx.Toolbar
  • Last Updated : 15 May, 2020

In this article we are going to lean 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 :

ParameterInput TypeDescription
toolidintID of the tool to enable or disable, as passed to AddTool .
enableboolIf True, enables the tool, otherwise disables it.

Code Example:




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 :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :