简体   繁体   中英

wxPython StaticText added to sizer

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.

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.

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM