Friday, October 24, 2025
HomeLanguageswxPython | InsertSeparator() function in wx.ToolBar

wxPython | InsertSeparator() function in wx.ToolBar

In this article we are going to learn about to learn about InsertSeparator() function associated with wx.ToolBar class of wxPython. InsertSeparator() function simply inserts the separator into the toolbar at the given position. Note that you must call Realize for the change to take place. It takes only pos as argument.

Syntax:

wx.ToolBar.InsertSeparator(self, pos)

Parameter :

Parameter Input Type Description
pos int position to insert separation starting from 0.

Return Type:

wx.ToolBarToolBase

Code Example 1: 

Python3




import wx
 
class Example(wx.Frame):
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.toolbar = self.CreateToolBar()
        td = self.toolbar.AddTool(1, '', wx.Bitmap('sep.png'))
        te = self.toolbar.AddTool(2, '', wx.Bitmap('right.png'))
        tf = self.toolbar.AddTool(3, '', wx.Bitmap('wrong.png'))
 
        self.toolbar.Realize()
        self.Bind(wx.EVT_TOOL, self.OnOne, td)
 
        self.SetSize((350, 250))
        self.SetTitle('Undo redo')
        self.Centre()
 
    def OnOne(self, e):
        # insert separator b / w tick and cross tool
        self.toolbar.InsertSeparator( pos = 2)
        self.toolbar.Realize()
 
    def OnQuit(self, e):
        self.Close()
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output: before clicking separate icon: after clicking separate icon: Code Example 2: 

Python3




import wx
 
class Example(wx.Frame):
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.toolbar = self.CreateToolBar()
        td = self.toolbar.AddTool(1, '', wx.Bitmap('sep.png'))
        te = self.toolbar.AddTool(2, '', wx.Bitmap('right.png'))
        tf = self.toolbar.AddTool(3, '', wx.Bitmap('wrong.png'))
 
        self.toolbar.Realize()
        self.Bind(wx.EVT_TOOL, self.OnOne, td)
 
        self.SetSize((350, 250))
        self.SetTitle('Undo redo')
        self.Centre()
 
    def OnOne(self, e):
        for i in range(5):
            # insert 5 separator tick and cross tool
            self.toolbar.InsertSeparator( pos = 2)
            self.toolbar.Realize()
 
    def OnQuit(self, e):
        self.Close()
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output: before clicking separate icon: after clicking separate icon:

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