wxPython StaticText added to sizer

494 Views Asked by At

I have a sizer with headline :

    self.label = wx.StaticText(self, -1, _("Elements:"))
    sizer_1 = wx.FlexGridSizer(2, 5, 5, 10)
    sizer_1.Add(self.label, 0, 0, 0)

I have many other objects in the sizer which are added later on. I would like the label to be the only object in the first line of the sizer. No matter how much i played with the flags which are listed here I couldn't find out how to set it. (I don't want to scratch the label on the whole line)

I want it to be looked like this: (order/number of elements bellow is irreverent)

Elements
1 2 3 4 5 6 7
8 9 

at the moment what I get is:

Elements 1 2 3
4 5 6 etc...

numbers represents other objects text.

2

There are 2 best solutions below

0
On BEST ANSWER

Create a vertically oriented BoxSizer. Add the label and the FlexGridSizer to the BoxSizer. Set the box sizer as the sizer for your panel/frame/whatever instead of the FlexGridSizer . That should just about do it.

Nesting sizers inside of each other is a powerful and very useful thing to learn.

0
On

I'm not sure about python but with C++, we can use wxStaticBoxSizer as it support the label display, same as the LabelFrame in tkinter or group/frame in some other languages.

You should layout your gui by the other BoxSizer/GridBoxSizer first and then add StaticBoxSizer inside, you will got the better look.

Ex:

wxStaticBoxSizer *sizer = new wxStaticBoxSizer(wxVERTICAL, panel, "Label here");