Friday, October 10, 2025
HomeLanguagesPython – CreateToolBar() in wxPython

Python – CreateToolBar() in wxPython

In this article we will learn how can we add a toolbar in a frame. A toolbar in a gui application provides quick access to various important tools. We can create toolbar using CreateToolBar() function in wx.Frame class of wxPython.

Syntax : wx.Frame.CreateToolBar(self, style=TB_DEFAULT_STYLE, id=ID_ANY, name=ToolBarNameStr)

Parameters :

Parameter Input Type Description
style long The toolbar style.
id int The menu item identifier.
name string The toolbar window name.

Returns : A pointer to the toolbar if it was created successfully, None otherwise.

Code Example :




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
  
        self.InitUI()
  
    def InitUI(self):
  
        # create toolbar using CreateToolBar function
        toolbar = self.CreateToolBar()
        qtool = toolbar.AddTool(wx.ID_ANY, 'Welcome', wx.Bitmap('/Desktop/wxPython/images.png'))
        toolbar.Realize()
  
        self.SetSize((600, 400))
        self.SetTitle('Simple toolbar')
        self.Centre()
  
    def OnQuit(self, e):
        self.Close()
  
  
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
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS