Skip to content
Related Articles

Related Articles

Improve Article
wxPython | create control tool using CreateTool() function
  • Last Updated : 04 Jun, 2020

In this function we are going to learn how can we create contro tool using CreateTool() function. It is another version of CreateTool() function which only takes two parameters that is control and label. Let’s see parameters in detail.

Parameters :

ParameterInput TypeDescription
controlwx.ControlThe control to be added.
labelstringText to be displayed near the control.


wx.ToolBar.CreateTool(self, control, label)

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()
        # declare control
        ctrl = wx.Control(self.toolbar, id = 19, pos = wx.DefaultPosition, size = wx.DefaultSize, style = 0, name ='control')
        # create control tool
        self.ptool = self.toolbar.CreateTool(ctrl, "control")
        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 control tool
        self.btn.SetLabel("Added tool")
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output :
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 :