Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78966

Re: Make a colour blink

Date 2014-10-10 20:24 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Make a colour blink
References <4b06699a-8852-4389-8a46-f0d2659322e1@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.14763.1412969051.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-10-10 19:51, cruzud@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:
>
> 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
(untested):

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:
http://effbot.org/tkinterbook/widget.htm

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Make a colour blink cruzud@gmail.com - 2014-10-10 11:51 -0700
  Re: Make a colour blink MRAB <python@mrabarnett.plus.com> - 2014-10-10 20:24 +0100
  Re: Make a colour blink Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-10 20:25 +0100
    Re: Make a colour blink Ulisses <cruzud@gmail.com> - 2014-10-10 12:45 -0700

csiph-web