GridBagSizer - Left size is not shared on all column (with growable)

Hello,
Little problem with AddGrowableCol. I do a example grid 2x2 :

On first line, two widget, one in each column (with expand flag).
On second line, one widget but span on two column and with a width more that the first two widget minsize.
Add AddGrowableCol(0) and AddGrowableCol(1)

The result, when the window show, give me that the widget on first line, second column, take all left space. The left space is not shared for all columns with growable.

Note, once the windows showed, the resizing on window keep proportion but with the incorrect size.

So, why the left size is not shared on the two column instead on the last column ?

Version wx : 4.1.0 msw (phoenix) wxWidgets 3.1.4

class MyFrame(wx.Frame):
	def __init__(self, parent, id, **dictArg):
		super(MyFrame, self).__init__(parent, title = "test") 
		
		self.panel = wx.Panel(self, -1 )
		
		self.sizerGrid = wx.GridBagSizer(1, 1)
		
		self.btn1 = wx.Button(self.panel, -1, "1" )
		self.sizerGrid.Add( self.btn1, (0,0), flag=wx.EXPAND )
		self.btn2 = wx.Button(self.panel, -1, "2" )
		self.sizerGrid.Add( self.btn2, (0,1), flag=wx.EXPAND )
		
		self.txtEntry = wx.TextCtrl(self.panel, -1, "", size=(250,-1) )
		self.sizerGrid.Add( self.txtEntry, (1,0), (2,2), flag=wx.EXPAND )
		
		self.sizerGrid.AddGrowableCol(0)
		self.sizerGrid.AddGrowableCol(1)
		
		self.panel.SetSizerAndFit(self.sizerGrid)
		self.Fit()

		self.Show()
	
if __name__ == '__main__':
	app = wx.App()
	frame = MyFrame(None, -1)
	app.MainLoop()

Don’t set the TextCtrl to a given size. The 250 pixels width assignment has an influence on the layout algorithm.
P.S.: Alternatively, give the buttons the same width of 125 pixels each.

This is a example, for expose the problem.
The real code is more complex that 2x2. :slight_smile:

And why the left space go in last cell on init (only on init), but after the left space is “share” on all growable col (or row) ?

Normally, I don’t need to specified explicite width. So, it’s a bug or I must coding for calculating all width on all column just on start (instead of wxpython) ?

In your example code you are setting the width and this is causing the imbalance: size=(250,-1)

You probably want more than the minimum width. You can get this by using code like this instead of sizing the TextCtrl:

        self.panel.SetSizer(self.sizerGrid)
        self.Layout()
        self.SetClientSize( (250, self.panel.GetBestSize()[1]) )