Hi, new to wxPython, and getting very frustrated trying to make a wx.Grid resize correctly!
It’s a simple horizontal list, and I want a fixed number of colums to resize to fit the space available. It’s working fine when the window is expanded, but when the window is shrunk the grid does not shrink - it just goes off the edge of the window!
Here is my minimal code - any help much appreciated.
Martin
import wx
import wx.grid
class NumberList(wx.grid.Grid):
def init(self, parent):
super(NumberList, self).init(parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
self.n=10
self.CreateGrid(1, self.n)
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
self.Bind(wx.EVT_SIZE, self.on_size)
Set small initial size for columns - will increase when we get resize event
for i in range(self.n):
self.SetColSize(i, 20)
def on_size(self, event):
event.Skip()
w, h = self.GetClientSize()
cw = w / self.n
for i in range(self.n):
self.SetColSize(i, cw)
self.Refresh()
class Gui(wx.Frame):
def init(self):
wx.Frame.init(self, None, title=“test”, size=(800, 400))
sizer = wx.GridBagSizer(vgap=5, hgap=10)
sizer.Add(wx.StaticText(self, label=“Data”), (0, 0))
sizer.Add(NumberList(self), pos=(0, 1), span=(1,2), flag=wx.EXPAND)
sizer.AddGrowableCol(2, 1)
self.SetSizer(sizer)
self.Layout()
if name == ‘main’:
app = wx.App(redirect=False)
top = Gui()
top.Show()
app.MainLoop()