get sizer for StaticBox

34 views
Skip to first unread message

John Lane

unread,
Apr 25, 2017, 4:08:18 PM4/25/17
to wx-users
I'm using a static box and static box sizer. I think I'm using the
correct pattern:

box = wx.StaticBox(self.content, id, name = name)
sizer = wx.StaticBoxSizer(box, orient = wx.VERTICAL)
self.content_sizer.Add(sizer, flag=wx.EXPAND)

I can then proceed to populate the box, for example:

sizer.Add(wx.StaticText(box, wx.ID_ANY, name='foo'))

Everything to this point works just fine.

Now, at some point later in the program, I need to add some more stuff
inside the static box. I can find the box:

box = next((b for b in self.content.GetChildren() if b.GetName() ==
some_name), None)

But I cannot get the sizer. I tried

sizer = box.GetSizer()

but it returns None.

How, given a StaticBox, can I get its sizer ?

Igor Korot

unread,
Apr 25, 2017, 6:14:50 PM4/25/17
to wx-u...@googlegroups.com
Hi,
Which version of wxPython?

Thank you.

>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users

Vadim Zeitlin

unread,
Apr 26, 2017, 8:29:54 AM4/26/17
to wx-u...@googlegroups.com
On Fri, 21 Apr 2017 20:30:17 +0100 John Lane wrote:

JL> I'm using a static box and static box sizer.
...
JL> But I cannot get the sizer. I tried
JL>
JL> sizer = box.GetSizer()
JL>
JL> but it returns None.
JL>
JL> How, given a StaticBox, can I get its sizer ?

You need to use GetContainingSizer() because this sizer actually contains
both the static box and the other windows appearing inside it (but which
are actually box's siblings, not children).

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

John Lane

unread,
May 2, 2017, 3:26:29 PM5/2/17
to wx-u...@googlegroups.com
On 26/04/17 13:29, Vadim Zeitlin wrote:

> JL> How, given a StaticBox, can I get its sizer ?
>
> You need to use GetContainingSizer() because this sizer actually contains
> both the static box and the other windows appearing inside it (but which
> are actually box's siblings, not children).
>
> Regards,
> VZ
>

Thanks, I worked that out myself a few hours after posing the question.
I do find the relationship between widgets and sizers confusing at times!

Reply all
Reply to author
Forward
0 new messages