Skip to content
Related Articles

Related Articles

Improve Article
wxPython | CreateTool() function in wx.Toolbar
  • Last Updated : 04 Jun, 2020

In this particular article we are going to learn about CreateTool() function in wx.ToolBar class in wxPython. CreateTool() function is a factory function to create a new toolbar tool. CreateTool() function only creates a tool which is further added using AddTool() function.

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

Parameters :

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


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()
        # create a tool using CreateTool() function
        self.ptool = self.toolbar.CreateTool(12,
                                             wx.Bitmap('path / wxPython / right.png'),
                                             shortHelp ="Simple Tool")
        self.btn = wx.Button(pnl, label ='Add created tool', pos =(20, 20))
        self.btn.Bind(wx.EVT_BUTTON, self.Onclick)
        self.SetSize((350, 250))
    def Onclick(self, e):
        # Add toolbar tool using AddTool() function
        self.btn.SetLabel("Added tool")
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

On starting Application:

On clicking button:

 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 :