I would like to use a grid as a subwindow within a frame using sizers,
but in my attempts to do this, I can't get both the sizing and the
scrollbars to work together. Specifically, I would like the grid
window to be sized to exactly fit the cells in the horizontal
direction, and then to scroll in the vertical direction.
I've tried many combinations of Fit, FitInside, Layout, SetScrollbars,
SetVirtualSize, EXPAND, VSCROLL, etc, but just can't seem to get this
right. For example, the attempt below fits the grid correctly in the
horizontal direction but doesn't scroll in the vertical.
(Here, I'm using a Mac, Python 2.5, and wxPython 2.8.10.1)
import wx
import wx.grid as gridlib
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Grid Test", size=(700,
450))
grid_window = MyGrid(self)
btn_ok = wx.Button(self, -1, "OK")
svert_sizer = wx.BoxSizer(wx.VERTICAL)
svert_sizer.Add(grid_window, 0)
rvert_sizer = wx.BoxSizer(wx.VERTICAL)
rvert_sizer.Add(btn_ok, 1, wx.EXPAND)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(rvert_sizer, 1)
sizer.Add(svert_sizer, 0, wx.EXPAND)
sizer.Add((20,20))
self.SetSizer(sizer)
class MyGrid(gridlib.Grid):
def __init__(self, parent):
gridlib.Grid.__init__(self, parent, -1, style=wx.VSCROLL)
self.SetDefaultColSize(60)
self.SetDefaultRowSize(30)
self.CreateGrid(50, 7)
if __name__=="__main__":
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None)
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()