HomeLanguageswxPython – InsertStretchableSpace() function in wx.ToolBar

wxPython – InsertStretchableSpace() function in wx.ToolBar

In this article we are going to learn about InsertStretchableSpace() function associated with wx.ToolBar class of wxPython. InsertStretchableSpace() inserts a stretchable space at the given position. Note that change will take place after Realize() is called. It takes only pos as parameter.

Syntax:

wx.ToolBar.InsertStretchableSpace(self, pos)

Parameters :

Parameter Input Type Description
pos int Position of tool to be added starting from 0.

Return Type:

wx.ToolBarToolBase
Code Example 1:




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('wrong.png'))
        tf = self.toolbar.AddTool(3, '', wx.Bitmap('right.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 stretchable space b / w separate 
        # and tick tool at position 1
        self.toolbar.InsertStretchableSpace(pos = 1)
        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 tool:

after clicking separate tool:

Code Example 1:




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('wrong.png'))
        tf = self.toolbar.AddTool(3, '', wx.Bitmap('right.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 stretchable space b / w tick and cross tool at position 2
        self.toolbar.InsertStretchableSpace(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 tool:

after clicking separate tool:

Last Updated :
01 Jun, 2020
Like Article
Save Article

<!–

–>

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

Most Popular

Dominic
32703 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7076 POSTS0 COMMENTS
Nicole Veronica
12211 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12303 POSTS0 COMMENTS
Shaida Kate Naidoo
7197 POSTS0 COMMENTS
Ted Musemwa
7457 POSTS0 COMMENTS
Thapelo Manthata
7174 POSTS0 COMMENTS
Umr Jansen
7161 POSTS0 COMMENTS