Open In App

wxPython | AddStretchableSpace() function in wx.ToolBar

Improve
Improve
Like Article
Like
Save
Share
Report

In this particular article we are going to learn about AddStretchableSpace() function of wx.ToolBar class of wxPython. AddStretchableSpace() adds a space between Tools in toolbar. Any space not taken up by the fixed items (all items except for stretchable spaces) is distributed in equal measure between the stretchable spaces in the toolbar. The most common use for this method is to add a single stretchable space before the items which should be right-aligned in the toolbar, but more exotic possibilities are possible, e.g. a stretchable space may be added in the beginning and the end of the toolbar to centre all toolbar items.

Syntax :

wx.ToolBar.AddStretchableSpace(self)

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()
        ptool = self.toolbar.AddTool(12, 'left', wx.Bitmap('/home/wxPython/right.png'), 
                                                        shortHelpString ="Simple Tool")
  
        # Add stretchable space using AddStretchableSpace()
        qtool = self.toolbar.AddStretchableSpace()
        rtool = self.toolbar.AddSimpleTool(12, 'right', wx.Bitmap('/home/wxPython/wrong.png'),
                                                              shortHelpString ="Simple Tool")
  
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
          
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output :



Last Updated : 17 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads