Add Horizontal Space to wx.BoxSizer

A wx.StaticBoxSizer holds two BoxSizers. The first row has 4 widgets and
sets the StaticBoxSizer width. The second row has 3 widgets, left aligned.

   I'm trying to center the second row within the StaticBoxSizer width, but
using Sizer.AddSpacer(size, 0, 0) prior to addting the second row's widgets
increases the vertical space between the two rows rather than adding space
to the left side of the second row.

   Because I'm not finding the proper method to do this I will appreciate a
clue stick.

TIA,

Rich

A small sample would help, but …

···

On Wed, May 20, 2015 at 10:30 AM, Rich Shepard rshepard@appl-ecosys.com wrote:

A wx.StaticBoxSizer holds two BoxSizers. The first row has 4 widgets and

sets the StaticBoxSizer width. The second row has 3 widgets, left aligned.

I’m trying to center the second row within the StaticBoxSizer width,

If I what you want right, you can add two spacers to the second row BoxSizer – it’s wx.HORIZONTAL, yes?

(untested)

second_row = wx.BoxSizer(wx.HORIZONTAL)

second_row.Add((1,1), 1)

second_row.Add(Window1, 0)

second_row.Add(Window2, 1)

second_row.Add(Window3, 1)

second_row.Add((1,1), 1)

that way, the spaders on the end will expand, with equal weights, to fit the space allocated, centering the three inner Windows.

Note that you MAY also be able to do this by adding the second row with the flag: wx.ALIGN_CENTER_HORIZONTAL

HTH,

-Chris

but

using Sizer.AddSpacer(size, 0, 0) prior to addting the second row’s widgets

increases the vertical space between the two rows rather than adding space

to the left side of the second row.

Because I’m not finding the proper method to do this I will appreciate a

clue stick.

TIA,

Rich

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

If I what you want right, you can add two spacers to the second row
BoxSizer -- it's wx.HORIZONTAL, yes?

Chris,

   Yep ... horizontal.

second_row = wx.BoxSizer(wx.HORIZONTAL)
second_row.Add((1,1), 1)
second_row.Add(Window1, 0)
second_row.Add(Window2, 1)
second_row.Add(Window3, 1)
second_row.Add((1,1), 1)

   I had a vague recollection of doing something like this in the past but
was not able to find a local (or Web) example.

Note that you MAY also be able to do this by adding the second row with
the flag: wx.ALIGN_CENTER_HORIZONTAL

   Didn't know this would work in less than a top level window. But, it's
worth a try.

Many thanks,

Rich

···

On Wed, 20 May 2015, Chris Barker wrote:

Chris,

   This worked perfectly. Here's the line of code:

   sb1Sizer.Add(d2Box, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)

where sb1Sizer is the StaticBoxSizer and d2Box is the second row of widgets
in that static box sizer.

Many thanks,

Rich

···

On Wed, 20 May 2015, Chris Barker wrote:

Note that you MAY also be able to do this by adding the second row with
the flag: wx.ALIGN_CENTER_HORIZONTAL