Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3309490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:38:49+00:00 2026-05-17T21:38:49+00:00

I’ve got a wxpython grid, and I’m changing the background color of a cell

  • 0

I’ve got a wxpython grid, and I’m changing the background color of a cell to show that something has happened to it.

I’d like to fade the color change in/out (like JavaScript in the browser) for a smoother look. Is this possible to do?

Right now, I’m just changing the background color, and then changing it back after a 1.5-second interval.

def do_stuf(self):
    # ... stuff ...
    wx.CallAfter(self.HighlightCell, row, col)

def HighlightCell(self, row, col):
    self.grid.Table.highlight = (row, col)
    self.grid.ForceRefresh()
    wx.CallLater(1500, self.ClearCellHighlight)

def ClearCellHighlight(self):
    self.grid.Table.highlight = None
    self.grid.ForceRefresh()

Then in the virtual table, I check if the cell needs highlighting:

def GetAttr(self, row, col, kind):
    """
    Use this callback to set the cell's background color
    """
    attr = wx.grid.GridCellAttr()
    if (row, col) == self.highlight:
        attr.SetBackgroundColour("green")
    elif row % 2:
        attr.SetBackgroundColour("white")
    else:
        attr.SetBackgroundColour("#e7ffff")

    return attr

Alternatively, is there another pretty way to indicate that a cell’s contents have changed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:38:50+00:00Added an answer on May 17, 2026 at 9:38 pm

    This is something I did a while ago to get a ListCtrl with items that fade out when deleted. Save the code to fade.py and run it to see the demo. Shouldn’t be too hard to adapt it to a Grid.

    import wx
    
    class FadeMixin(object):
        ''' FadeMixin provides one public method: DeleteItem. It is meant to
        be mixed in with a ListCtrl to 'fade out' items before they are
        really deleted. Mixin like this:
    
        Assumption: the background colour of the control is wx.WHITE
    
        class MyListCtrl(FadeMixin, wx.ListCtrl):
            ...
        '''
        def __init__(self, *args, **kwargs):
            self.__bgColour = wx.WHITE
            super(FadeMixin, self).__init__(*args, **kwargs)
    
        def DeleteItem(self, index, fadeStep=10, fadeSpeed=50):
            if self.IsEnabled():
                self.__startDeleteItem(index)
            fgColour, bgColour, transparentColour = self.__getColours(index)
            if fgColour == bgColour == transparentColour:
                self.__finishDeleteItem(index)
            else:
                for colour, setColour in [(fgColour, self.SetItemTextColour), 
                                          (bgColour, self.SetItemBackgroundColour)]:
                    fadedColour = self.__fadeColour(colour, transparentColour, 
                                                    fadeStep)
                    setColour(index, fadedColour)
                wx.FutureCall(50, self.DeleteItem, index, fadeStep, fadeSpeed)
    
        def SetBackgroundColour(self, colour):
            self.__bgColour = colour
            super(FadeMixin, self).SetBackgroundColour(colour)
    
        def GetBackgroundColour(self):
            return self.__bgColour
    
        def __startDeleteItem(self, index):
            # Prevent user input during deletion. Things could get messy if
            # the user deletes another item when we're still busy fading out the 
            # first one:
            self.Disable()
            # Unselect the item that is to be deleted to make the fading visible:
            currentState = self.GetItemState(index, wx.LIST_STATE_SELECTED)
            self.SetItemState(index, ~currentState, wx.LIST_STATE_SELECTED)
    
        def __finishDeleteItem(self, index):
            super(FadeMixin, self).DeleteItem(index)
            self.Enable()
    
        def __getColours(self, index):
            fgColour = self.GetItemTextColour(index)
            bgColour = self.GetItemBackgroundColour(index)
            transparentColour = self.GetBackgroundColour()
            if not bgColour:
                bgColour = transparentColour
            return fgColour, bgColour, transparentColour
    
        def __fadeColour(self, colour, transparentColour, fadeStep):
            newColour = []
            for GetIntensity in wx.Colour.Red, wx.Colour.Green, wx.Colour.Blue:
                currentIntensity = GetIntensity(colour) 
                transparentIntensity = GetIntensity(transparentColour)
                if currentIntensity < transparentIntensity:
                    newIntensity = min(transparentIntensity,
                                       currentIntensity + fadeStep)
                elif currentIntensity > transparentIntensity:
                    newIntensity = max(transparentIntensity, 
                                    currentIntensity - fadeStep)
                else:
                    newIntensity = transparentIntensity
                newColour.append(newIntensity)
            return wx.Colour(*newColour)
    
    
    class ListCtrl(FadeMixin, wx.ListCtrl):
        pass
    
    
    class Frame(wx.Frame):
        def __init__(self, *args, **kwargs):
            super(Frame, self).__init__(*args, **kwargs)
            self.list = ListCtrl(self, style=wx.LC_REPORT)
            self.list.InsertColumn(0, 'Column 0')
            self.list.InsertColumn(1, 'Column 1')
            self.fillList()
            self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelected)
            self.Bind(wx.EVT_LIST_DELETE_ITEM, self.onDeleted)
    
        def onSelected(self, event):
            self.list.DeleteItem(event.GetIndex())
    
        def onDeleted(self, event):
            if self.list.GetItemCount() == 1:
                wx.CallAfter(self.fillList, False)
    
        def fillList(self, firstTime=True):
            for row in range(10):
                self.list.InsertStringItem(row, 'Item %d, Column 0'%row)
                self.list.SetStringItem(row, 1, 'Item %d, Column 1'%row)
            self.list.SetItemBackgroundColour(1, wx.BLUE)
            self.list.SetItemTextColour(2, wx.BLUE)
            self.list.SetItemBackgroundColour(3, wx.GREEN)
            self.list.SetItemTextColour(4, wx.GREEN)
            self.list.SetItemBackgroundColour(5, wx.RED)
            self.list.SetItemTextColour(6, wx.RED)
            self.list.SetItemBackgroundColour(7, wx.BLACK)
            self.list.SetItemTextColour(7, wx.WHITE)
            self.list.SetItemBackgroundColour(8, wx.WHITE)
            self.list.SetItemTextColour(8, wx.BLACK)
            if not firstTime:
                self.list.SetBackgroundColour(wx.BLUE)
    
    
    app = wx.App(False)
    frame = Frame(None, title='Select an item to fade it out')
    frame.Show()
    app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.