Hi,
I had asked a similar question here, but this one is slightly different.
I have a frame and a grid on it. Although I use wx.EXPAND
flag and SetSizerAndFit
and Layout
methods, the frame doesn’t display the grid columns completely. There appears a horizontal scroll bar on the grid, and user has to scroll to right to display all grid columns.
Why does the system behave this way at start up? How to solve it?
import wx
import wx.grid as grid_lib
import wx.lib.agw.flatnotebook as fnb
class TheFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "The Frame", #size=(600, 600),
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX
)
self.sizer = wx.BoxSizer(wx.VERTICAL)
grid_sizer = self.create_grid()
self.sizer.Add(grid_sizer, 1, wx.EXPAND)
self.SetSizerAndFit(self.sizer)
self.Layout()
def create_grid(self):
self.current_row = None
grid_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.grid = grid_lib.Grid(self, -1, name="grid")
self.grid.CreateGrid(0, 15)
self.grid.DisableDragColSize()
self.grid.DisableDragRowSize()
self.grid.HideRowLabels()
self.grid.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
col_labe_font = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, faceName="Calibri")
self.grid.SetLabelFont(col_labe_font)
grid_sizer.Add(self.grid, 0, wx.EXPAND)
for i in range(100):
self.grid.AppendRows(1)
self.grid.Refresh()
grid_sizer.Layout()
return grid_sizer
if __name__ == "__main__":
app = wx.App(False)
frame = TheFrame()
frame.Show()
app.MainLoop()