markbse
markbse

Reputation: 1123

How to align 2 toolbars on same the row, one aligned left and one aligned right?

I use wxPython to sketch up a user interface for the a python program. I need to put 2 toolbars on the same row. One toolbar is on the left while the other is on the right.

I use BoxSizer to achieve this (by putting a stretchable space between 2 toolbars)

However, the stretchable space produces a blank space between 2 toolbars and there is no underline for that space, hence, it looks ugly. (Please prefer to this picture to know what I mean http://i55.tinypic.com/2dlrvaa.jpg).

The underlines are supposed to be connected to each other so that they look like just one toolbar in total. They are discrete because of the stretchable space.

Is there any solution I can try to overcome this? I guess I can either remove the underlines for the toolbar, or add underline to the blank space. However I don't know how to achieve either way of these.

Here is part of my code:

# Create the top toolbar container
topToolBar = wx.BoxSizer(wx.HORIZONTAL)

# Add 2 toolbars to this sizer, with stretchable space 
# We add the same toolbar for testing purpose
topToolBar.Add(toolbar1,0,wx.ALIGN_LEFT,4) # add the toolbar to the sizer
topToolBar.AddStretchSpacer()
topToolBar.Add(toolbar1,0,wx.ALIGN_RIGHT ,4)

self.SetSizer(topToolBar)    

Upvotes: 2

Views: 1777

Answers (1)

Peter Gibson
Peter Gibson

Reputation: 19564

It's been a while since I used wxPython, but have you tried removing the spacer and setting the proportion of the first toolbar to greater than that of the second? Eg

topToolBar.Add(toolbar1,1,wx.ALIGN_LEFT,4) # note the 2nd param 'proportion' is 1
#topToolBar.AddStretchSpacer()
topToolBar.Add(toolbar1,0,wx.ALIGN_RIGHT,4)

The idea being that the first toolbar expands to fill the available space.

Upvotes: 4

Related Questions