Make a colour blink
python at mrabarnett.plus.com
Fri Oct 10 21:24:01 CEST 2014
On 2014-10-10 19:51, cruzud at gmail.com wrote:
> Hello. I'm trying to make a colour blink when an event occurs.
> But the program is displaying only the last colour:
> def blink(self, event=None):
> lbl['background'] = 'red'
> 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.
lbl.['background'] = 'SystemButtonFace'
Have a look here:
More information about the Python-list