如何设置wxPython网格背景色?

如何设置wxPython网格背景色?,python,wxpython,wxwidgets,Python,Wxpython,Wxwidgets,我正在使用wxPython网格,但我无法设置它的背景色(未填充单元格的网格部分)。我试过用grid.setbackgroundcolor,但运气不好;显示的背景色始终是windows的默认系统颜色 wx.version()->2.8.10.1(msw unicode) sys.version->2.5(r25:51908,2006年9月19日,09:52:17)[MSC v.1310 32位(英特尔)] O/S版本->Windows XP SP3,但我尝试使用基于Ubuntu的Python li

我正在使用wxPython网格,但我无法设置它的背景色(未填充单元格的网格部分)。我试过用grid.setbackgroundcolor,但运气不好;显示的背景色始终是windows的默认系统颜色

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

sys.version->2.5(r25:51908,2006年9月19日,09:52:17)[MSC v.1310 32位(英特尔)]

O/S版本->Windows XP SP3,但我尝试使用基于Ubuntu的Python live cd,结果相同

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()
导入wx
导入wx.grid
类TestFrame(wx.Frame):
定义初始化(自):
wx.Frame.\uuuu init\uuuuu(self,None,title=“网格表”,size=(640480))
grid=wx.grid.grid(self,size=(300300))
grid.CreateGrid(2,2)
网格设置单元值(0,0,“1”)
颜色=(100100255)
attr=self.cellAttr=wx.grid.GridCellAttr()
属性设置背景颜色(颜色)
#为行,为列
对于xrange(2)中的行:
对于X范围内的列(2):
grid.SetAttr(行、列、属性)

grid.setBackgroundColor(color)#grid.setDefaultCellBackgroundColor(color)
将为所有内容上色,包括单元格外的区域。

使用
grid.setDefaultCellBackgroundColor(grid.getLabelBackgroundColor())
将所有内容上色。然后可以在单元格的基础上重新绘制网格。

效果很好,谢谢!在文档中的数百种颜色和颜色之间,我错过了这一点:)