Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: wxPython: Stretching StaticBox horizontally to fit frame

How do I stretch a static box to fit horizontally on the frame?

Code:

class XPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        self.box = wx.StaticBox(self, -1, "X CONTROL PANEL")
        self.bsizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)

        self.t = wx.StaticText(self, -1, "X command: ")
        self.cmdtext = wx.TextCtrl(self, -1, "")
        self.itpsend_btn = wx.Button(self, -1, "  Send  ")
        self.bsizer.Add(self.t, 0, wx.TOP|wx.LEFT, 10)
        self.bsizer.Add(self.cmdtext, 0 , wx.ALL|wx.EXPAND)
        self.bsizer.Add(self.itpsend_btn, 0, wx.ALL|wx.CENTER)

        self.border = wx.BoxSizer()
        self.border.Add(self.bsizer, -1, wx.EXPAND|wx.ALL, 25)
        self.SetSizer(self.border)

I'm getting this:

enter image description here

But I would like it to be strecthed in wide to fit the frame.

Please educate. Thanks.

like image 758
siva Avatar asked Jun 03 '26 10:06

siva


1 Answers

Your XPanel is correct. Your problem is not in XPAnel but in the frame that holds this and other panels (from your image there is at least and additional panel).

Is in the frame that you must tell the panel to expand and fit the full frame. So , you must use wx.EXPAND as shown here:

enter image description here

like image 65
joaquin Avatar answered Jun 06 '26 00:06

joaquin