Tuesday, June 9, 2026
HomeLanguageswxPython – AddControl() method in wx.ToolBar

wxPython – AddControl() method in wx.ToolBar

In this article we are going to learn about AddControl() function in wx.ToolBar class in wxPython. AddControl() creates a control in toolbar. A Control is generally a small window which processes user input and/or displays one or more item of data.

Syntax :

wx.ToolBar.AddControl(self, control, label="")

Parameters :

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

Return Type : wx.ToolBarToolBase

Code Example :




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()
  
        ctrl = wx.Control(self.toolbar, 21
                          wx.DefaultPosition, 
                          wx.DefaultSize, 
                          style = 0
                          name = 'control')
  
        qtool = self.toolbar.AddTool(12, 'Quit'
                  wx.Bitmap('/home/wxPython/right.png'))
  
        # Add control using AddControl() method
        rtool = self.toolbar.AddControl(ctrl, 'control')
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Simple toolbar')
        self.Centre()
          
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output :

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

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS