Make a colour blink

MRAB python at
Fri Oct 10 21:24:01 CEST 2014

On 2014-10-10 19:51, cruzud at wrote:
> Hello. I'm trying to make a colour blink when an event occurs.
> But the program is displaying only the last colour:
> self.bttn.bind('<ButtonRelease-Return>',blink)
> def blink(self, event=None):
>      lbl['background'] = 'red'
>      sleep(0.5)
>      lbl.['background'] = 'SystemButtonFace'
> Can you help?
You shouldn't use sleep like that because it'll block the event loop.

Instead, you should use a timed callback that will reset the colour
after a certain amount of time has elapsed, something like this

def blink(self, event=None):
     lbl['background'] = 'red'

     # Assuming that 'main_window' is the main window...
     main_window.after(500, reset_color) # Time in milliseconds.

def reset_color():
     lbl.['background'] = 'SystemButtonFace'

Have a look here:

More information about the Python-list mailing list