BoxSizer Alignment

Hi Guys,
I am sure I am being silly!

I want wx.BoxSizer to align adjacent boxes top and bottom and I do not see a way.

This is the substance of what I have tried. Where
     def tempBox(self, size):
         box_title = wx.StaticBox(self.mainpanel, -1, "temp")
         box = wx.StaticBoxSizer(box_title, wx.VERTICAL)
         t = wx.StaticText(self.mainpanel, -1, "temp top left")
         t1 = wx.StaticText(self.mainpanel, -1, "temp Bottom Right")
         box.Add(t, 0, wx.TOP|wx.LEFT, 10)
         box.Add(t1, 0, wx.TOP|wx.LEFT, size)
         return box

box1 = self.tempBox(100)
box1 = self.tempBox(200)

align = wx.TOP | wx.LEFT | wx.ALIGN_TOP | wx.ALIGN_BOTTOM
s = wxBoxSizer(wx.HORIZONTAL)
s.Add(box1, 0, align, 5)
s.Add(box2, 0, align, 5)

So, although the boxes are arranged to be different sizes I would like them to be vertically sized to the largest.

Help appreciated

Nigel King

I have spent hours on this and as soon as I send the message I come up with the solution.
align = wx.TOP | wx.LEFT | wx.EXPAND

Sorry for any trouble

Nigel King

···

On 30 Aug 2005, at 14:29, Nigel King wrote:

Hi Guys,
I am sure I am being silly!

I want wx.BoxSizer to align adjacent boxes top and bottom and I do not see a way.

This is the substance of what I have tried. Where
    def tempBox(self, size):
        box_title = wx.StaticBox(self.mainpanel, -1, "temp")
        box = wx.StaticBoxSizer(box_title, wx.VERTICAL)
        t = wx.StaticText(self.mainpanel, -1, "temp top left")
        t1 = wx.StaticText(self.mainpanel, -1, "temp Bottom Right")
        box.Add(t, 0, wx.TOP|wx.LEFT, 10)
        box.Add(t1, 0, wx.TOP|wx.LEFT, size)
        return box

box1 = self.tempBox(100)
box1 = self.tempBox(200)

align = wx.TOP | wx.LEFT | wx.ALIGN_TOP | wx.ALIGN_BOTTOM
s = wxBoxSizer(wx.HORIZONTAL)
s.Add(box1, 0, align, 5)
s.Add(box2, 0, align, 5)

So, although the boxes are arranged to be different sizes I would like them to be vertically sized to the largest.

Help appreciated

Nigel King

I have spent hours on this and as soon as I send the message I come up with the solution.
align = wx.TOP | wx.LEFT | wx.EXPAND

Sorry for any trouble

no trouble at all... :slight_smile: it happens to a lot of us :wink: myself included :o)

Nigel King

Peter.

···

On Tue, 30 Aug 2005 16:34:42 +0300, Nigel King <King@dircon.co.uk> wrote:

I second Peter's comment, with Yeah, me 2!

But! It keeps getting easier and easier to do stuff with sizers.

Took me the longest time to get comfortable with the 4th parameter, but now I enjoy it!

Furthermore, I've become fond of AddMany, tho I doubt there is much of a speed improvement, nominal if any, but I think it enhances readability and reduces code.

self.textctl = wx.TextCtrl(self, -1)
self.textctl2 = wx.TextCtrl(self, -1)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.AddMany([
     wx.StaticText(self, -1, 'label'),
     (self.txtctl, 0, wx.EXPAND | wx.BOTTOM, 3),
     (wx.StaticText(self, -1, 'label2'), 0, wx.ALIGN_CENTERE),
     (self.txtctl2, 0, wx.EXPAND | wx.BOTTOM, 3),
     ])

wx.ALL, left/right, top/bottom affect where the space padding (parameter 4) is applied.

FWIW, you only needed to include wx.EXPAND for the size adjustment. If you wanted to add spacing around the widget, wx.ALL would be applicable if you included a value for parameter #4.

After this use finally sunk into my thick skull, it all makes better sense to me.

-Joe