Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It took me a while to figure this out. It's something that I do with wxPython all the time. Essentially you need to nest box sizers. You need one vertical box sizer that holds two horizontal box sizers.</p> <p>Here is the code you need:</p> <pre><code>import wx class sizertest(wx.Panel): def __init__(self,parent): wx.Panel.__init__(self,parent) vsizer = wx.BoxSizer(wx.VERTICAL) hsizer1 = wx.BoxSizer(wx.HORIZONTAL) button1 = wx.Button(self,-1,"button 1") self.Bind( wx.EVT_BUTTON,self.button1,button1) hsizer1.Add(button1,1,wx.EXPAND) button2 = wx.Button(self,-1,"button 2") self.Bind( wx.EVT_BUTTON,self.button2,button2) hsizer1.Add(button2,1,wx.EXPAND) vsizer.Add(hsizer1,.1,wx.EXPAND) self.SetSizer(vsizer) tc = wx.TextCtrl(self,-1,"",style=wx.TE_MULTILINE) hsizer2 = wx.BoxSizer(wx.HORIZONTAL) hsizer2.Add(tc,1,wx.EXPAND) vsizer.Add(hsizer2,1,wx.EXPAND) def button1(self,event):pass def button2(self,event):pass if __name__ == "__main__": app = wx.App() frame = wx.Frame(parent=None, id=-1, title="sizer test") panel = sizertest(frame) frame.Show() app.MainLoop() </code></pre> <p>The vertical sizer vsizer holds two horizontal sizers. The first horizontal sizer holds as many buttons as you want to add to it, and they can expand horizontally. Because you add it to the vertical sizer with a number less than one for its "weight" it will not expand vertically. The second horizontal sizer holds the text control, and it can expand to take up all the remaining horizontal and vertical space. Both sizers expand as the window is expanded.</p> <p>I recommend that you get the book wxPython in Action by Rappin and Dunn - it really helped me understand how the wxPython sizers and screen layout works.</p> <p>I use nested boxsizers for 99% of my wxPython programs.</p> <p>Curt</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload