Is more than one row attribute possible in wx.Grid? [RESOLVED}

    redText = wx.grid.GridCellAttr()
    blueText = wx.grid.GridCellAttr()
    bgColour = wx.grid.GridCellAttr()
    redText.SetTextColour('Red')
    blueText.SetTextColour('Blue')
    bgColour.SetBackgroundColour('Light Grey')

    if resultsBill[0] == '0':
        self.probGrid.SetRowAttr(rowNumber, redText)
    else: pass
    try:
        if resultsHCC[0] == 'Yes':
            self.probGrid.SetRowAttr(rowNumber, bgColour)   #this isn't working
            self.probGrid.SetRowAttr(rowNumber, redText)
        else:
            if resultsHCC[1] == 'Yes':
                self.probGrid.SetRowAttr(rowNumber, bgColour)
    except: pass

I can’t seem to get both the background color and the text color on the same row. Is the background getting overwritten?

Thanks for any help.

Mike Barron

Hi Mike,

Try setting both the text colour and background colour in a single GridCellAttr and then set that attr on the required row(s).

    hccText = wx.grid.GridCellAttr()
    blueText = wx.grid.GridCellAttr()
    rxText = wx.grid.GridCellAttr()
    hccText.SetTextColour('Red')
    hccText.SetBackgroundColour('Light Grey')
    blueText.SetTextColour('Blue')
    rxText.SetBackgroundColour('Light Grey')

    if resultsBill[0] == '0':
        self.probGrid.SetRowAttr(rowNumber, blueText)
    else: pass
    try:
        if resultsHCC[0] == 'Yes':
            self.probGrid.SetRowAttr(rowNumber, hccText)
        else:
            if resultsHCC[1] == 'Yes':
                self.probGrid.SetRowAttr(rowNumber, rxText)
            else: pass
    except: pass

Thanks Richard. This revision is now working correctly.

Mike