Skip to content
Related Articles
Open in App
Not now

Related Articles

wxPython – AddTool() function in wx.ToolBar

Improve Article
Save Article
  • Last Updated : 17 May, 2020
Improve Article
Save Article

AddTool() is another function in wx.ToolBar class of wxPython. AddTool() function simply adds a tool to the Toolbar. This is another version of AddTool() function with greater number of parameters. it adds parameters like : bmpDisabled, longHelp, clientData.

Syntax: wx.ToolBar.AddTool(self, id, label, bitmap, bmpDisabled=wx.NullBitmap, kind=wx.ITEM_NORMAL, shortHelp=””, longHelp=””, clientData=None)

Parameters :

ParameterInput TypeDescription
toolidintAn integer by which the tool may be identified in subsequent operations.
labelstringThe string to be displayed with the tool.
bitmapwx.bitmapThe primary tool bitmap.
bmpDisabledwx.bitmapThe bitmap used when the tool is disabled.
kindintkind of toolbar.
shortHelpstringThis string is used for the tools tooltip.
longHelpstringdetailed string associated with tool.
clientDataPyUserDataAn optional pointer to client data which can be retrieved later using GetToolClientData.

Code Example:

import wx
class Example(wx.Frame):
    global count
    count = 0;
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    def InitUI(self):
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        # Radio tool using AddTool() Function
        ptool = self.toolbar.AddTool(12, 'oneTool',  
                                  kind = wx.ITEM_RADIO, shortHelp ="Simple Tool")
        spc = self.toolbar.AddStretchableSpace()
        # Check tool using AddTool() Function
        qtool = self.toolbar.AddTool(12, 'oneTool',  wx.Bitmap('/home/wxPython/right.png'), 
                                             kind = wx.ITEM_CHECK, shortHelp ="Simple Tool")
        spc = self.toolbar.AddStretchableSpace()
        # Normal tool using AddTool() Function
        rtool = self.toolbar.AddTool(12, 'oneTool',  wx.Bitmap('/home/wxPython/right.png'),
                                           kind = wx.ITEM_NORMAL, shortHelp ="Simple Tool")
        self.SetSize((350, 250))
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output :

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!