如何设置wxPython网格背景颜色?

问题描述 投票:0回答:2

我正在使用wxPython网格,但我无法设置它的背景颜色(未填充单元格的网格部分)。我尝试使用grid.SetBackgroundColour,但没有运气;显示的背景颜色始终是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版本 - > 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()
python wxpython wxwidgets
2个回答
2
投票

grid.SetDefaultCellBackgroundColour(color)将为所有事物着色,包括细胞外的区域。


0
投票

使用grid.SetDefaultCellBackgroundColour(grid.GetLabelBackgroundColour())为相同颜色的所有颜色着色。然后可以基于单元格重新绘制网格。

© www.soinside.com 2019 - 2024. All rights reserved.