In this simple 3x3 example, I have a color chooser spanning the three columns in the first row. An empty second row and then a third row where the first column is empty and the next two have buttons. I set only the first column as growable. If you run the example, you’ll notice that the third column is quite a bit wider than the second, even though it contains the button that should require the least amount of space (I swapped the ok and cancel buttons intentionally). Can anyone explain this behavior? I would expect the 2nd and 3rd columns to only be wide enough to accommodate the buttons.
===================================== CODE ======================================================================
import wx
from wx.lib.colourchooser import PyColorChooser
class ColorChooserTransient(wx.Panel):
def init(self, parent, id=wx.ID_ANY):
wx.Panel.init(self, parent, id)
self._chooser = PyColorChooser(self, wx.ID_ANY)
sizer = wx.GridBagSizer(4, 4)
self._okButton = wx.Button(self, wx.ID_ANY, “Canel”)
self._cancelButton = wx.Button(self, wx.ID_ANY, “Ok”)
sizer.Add(self._chooser, (0,0), (1,3))
sizer.Add(self._okButton, (2,1), (1,1), wx.EXPAND | wx.BOTTOM, 5)
sizer.Add(self._cancelButton, (2,2), (1,1), wx.EXPAND | wx.BOTTOM, 5)
sizer.AddGrowableCol(0, 2)
sizer.AddGrowableRow(1, 1)
self.SetSizerAndFit(sizer)
if name == “main”:
from wx.lib.mixins.inspection import InspectionMixin
class TestApp(wx.App, InspectionMixin):
def OnInit(self):
self.Init()
frame = wx.Frame(None)
color = ColorChooserTransient(frame)
self.SetTopWindow(frame)
frame.Layout()
frame.Show()
return 1
app = TestApp()
app.MainLoop()
grid.py (1.24 KB)