views:

367

answers:

1

I'm working with a wxPython grid, but I cannot set the background color of it (the grid part that isn't filled with cells). I tried with grid.SetBackgroundColour, but without luck; the backcolor shown is always the default system color for windows.

wx.version() -> 2.8.10.1 (msw-unicode)

sys.version -> 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]

O/S version -> Windows XP SP3, but I tried with an Ubuntu based Python live cd with the same result.

import wx
import wx.grid

class TestFrame (wx.Frame):
    def __init__ (self):
        wx.Frame.__init__ (self, None, title="Grid Table", size=(640,480))

        grid = wx.grid.Grid(self, size=(300,300))
        grid.CreateGrid(2,2)
        grid.SetCellValue(0,0,"1")

        color = (100,100,255)
        attr = self.cellAttr = wx.grid.GridCellAttr()
        attr.SetBackgroundColour(color)

        # for row, col in
        for row in xrange(2):
            for col in xrange(2):
                grid.SetAttr(row, col, attr)

        grid.SetBackgroundColour(color)     # <<< This don't work!

app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
+1  A: 

grid.SetDefaultCellBackgroundColour(color) will color everything, including the area outside the cells.

interjay
Works great, thanks! I missed that between the hundreds of Colors and Colours in the docs :)
PabloG