wxPython | EnableTool() function in wxPython

In this article we are going to learn about EnableTool() function of wx.ToolBar class of wxPython. It is another important function in wx.Toolbar class. EnableTool() function is used to enable or disable a particular tool in Toolbar. It takes ‘enable’ bool parameter which is when true enable the tool and disable it while it is false.

Syntax:

wx.toolbar.EnableTool(self, ttolid, enable)

Parameters :

Parameter Input Type Description
toolid int An integer by which the tool may be identified in subsequent operations.
enable bool If True, enables the tool, otherwise disables it.

Code Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'twoTool', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool2")
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
  
        # disable tool in toolbar
        self.toolbar.EnableTool(13, False)
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

chevron_right


Output Window:



Code Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'twoTool', wx.Bitmap('user.png'), shortHelp ="Simple Tool2")
        stool = self.toolbar.AddTool(14, 'twoTool', wx.Bitmap('right.png'), shortHelp ="Simple Tool2")
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
  
        # disable tool in toolbar
        self.toolbar.EnableTool(13, False)
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

chevron_right


Output Window:

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.




My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.