I try to format a form using GridBaxSizer within a StaticBox. The grid has 2 rows and 4 columns, the input-fields with TextCtrl should use 3 cols and expand over the available space.
The span in tc1 and tc2 and the expand - flag does not have any influence on the width of tc1 and tc2. They appear only on the right hand side in the box.
I dont see where is the problem. Can someone help?
Here's the code:
import wx
class GbsTest(wx.Frame):
def __init__(self, parent, title):
super(GbsTest, self).__init__(parent, title=title, size=(800, 600))
self.InitUI()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer()
box = wx.StaticBox(panel, label='Demo')
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
gbs = wx.GridBagSizer(2, 4)
text2 = wx.StaticText(panel, label="Name")
gbs.Add(text2, pos=(1, 0), flag=wx.LEFT|wx.TOP, border=10)
tc1 = wx.TextCtrl(panel)
gbs.Add(tc1, pos=(1, 1), span=(1, 3), flag=wx.LEFT|wx.EXPAND)
text3 = wx.StaticText(panel, label="Package")
gbs.Add(text3, pos=(2, 0), flag=wx.LEFT|wx.TOP, border=10)
tc2 = wx.TextCtrl(panel)
gbs.Add(tc2, pos=(2, 1), span=(1, 3), flag=wx.LEFT|wx.EXPAND)
gbs.AddGrowableCol(0)
boxSizer.Add(gbs, flag=wx.EXPAND)
sizer.Add(boxSizer, pos=(0, 0), flag=wx.EXPAND | wx.ALL, border=5)
sizer.AddGrowableCol(0)
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.App()
GbsTest(None, title="GBS-Test")
app.MainLoop()
Your problem is that you are defining
gbs.AddGrowableCol(0)
.You are using column zero in
gbs
for the text that you are outputting and not theTextCtrl
fields, which are in column 1.Given that the text fields do not have the
wx.EXPAND
attribute you weren't seeing the issue.Change
gbs.AddGrowableCol(0)
togbs.AddGrowableCol(1)
and it function as you require.