Thursday, October 23, 2025
HomeLanguageswxPython | create control tool using CreateTool() function

wxPython | create control tool using CreateTool() function

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

Parameters : 

Parameter Input Type Description
control wx.Control The control is to be added.
label string Text to be displayed near the control.

Syntax:  

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

Code Example:  

Python3




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):
        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.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
 
    def Onclick(self, e):
        # Add control tool
        self.toolbar.AddTool(self.ptool)
        self.btn.SetLabel("Added tool")
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output : 
On starting Application: 

On clicking Button: 

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS