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:
<!–
–>

wxPython – change toolbar colour wx.ToolBar

wxPython – EnableTool() function in wx.Toolbar

wxPython – AddLabelTool() function in wx.ToolBar

wxPython – AddRadioTool() function in wx.ToolBar

wxPython | AddStretchableSpace() function in wx.ToolBar

wxPython – AddTool() function in wx.ToolBar

wxPython – ClearTools() function in wx.Toolbar

wxPython – AddSimpleTool() function in wx.ToolBar

wxPython – DeleteTool() function in wx.ToolBar

wxPython | DeleteToolByPos() function in wx.ToolBar



Please Login to comment…