Skip to content
Related Articles
Open in App
Not now

Related Articles

wxPython | AddStretchableSpace() function in wx.ToolBar

Improve Article
Save Article
  • Last Updated : 17 May, 2020
Improve Article
Save Article

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 :


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)
    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.SetSize((350, 250))
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output :

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!