Getting a WxPython panel item for extension

I have a WxPython frame containing one element, for example:

class Panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.text = wx.StaticText(self, label='Panel 1')

I have a frame containing several panels, including this one, and the sizes are controlled by sizers. I would like this to StaticTextexpand. Using BoxSizertext-only and setting the flag wx.EXPANDdoes the trick, but it seems silly to use sizer for only one element.

Any simpler solution?

(I could just add a StaticTextframe directly to the parent syntax, but for my design it makes sense to start with a frame directly).


I only realized that when creating BoxSizerwith a single element it does not work with wx.VERTICAL:

class Panel1(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.BackgroundColour = 'red'
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.Sizer = sizer
        self.list = wx.ListBox(self, choices=[str(i) for i in xrange(100)])
        sizer.Add(self.list, 0, wx.EXPAND)
        sizer.Fit(self)

, , , (, )?

: , , , . (.. 0 1 BoxSizer.Add .)

+3
1

A wx.Frame , . wx.Panel . sizer. , :

def expanded(widget, padding=0):
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(widget, 1, wx.EXPAND|wx.ALL, padding)
    return sizer

class Panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.text = wx.StaticText(self, label='Panel 1')
        self.SetSizer(expanded(self.text))

. .

+6

Source: https://habr.com/ru/post/1751438/


All Articles