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


Groups > comp.lang.python > #78962 > unrolled thread

Make a colour blink

Started bycruzud@gmail.com
First post2014-10-10 11:51 -0700
Last post2014-10-10 12:45 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  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

#78962 — Make a colour blink

Fromcruzud@gmail.com
Date2014-10-10 11:51 -0700
SubjectMake a colour blink
Message-ID<4b06699a-8852-4389-8a46-f0d2659322e1@googlegroups.com>
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?

[toc] | [next] | [standalone]


#78966

FromMRAB <python@mrabarnett.plus.com>
Date2014-10-10 20:24 +0100
Message-ID<mailman.14763.1412969051.18130.python-list@python.org>
In reply to#78962
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

[toc] | [prev] | [next] | [standalone]


#78967

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-10 20:25 +0100
Message-ID<mailman.14764.1412969124.18130.python-list@python.org>
In reply to#78962
On 10/10/2014 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?
>

Telling us what platform you're on, your OS, Python version and the 
actual GUI helps in cases like this.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#78970

FromUlisses <cruzud@gmail.com>
Date2014-10-10 12:45 -0700
Message-ID<50680f20-4c38-430c-9eae-a845102e3539@googlegroups.com>
In reply to#78967
> Telling us what platform you're on, your OS, Python version and the 
> 
> actual GUI helps in cases like this.
> 
> 
> 
> -- 
> 
> My fellow Pythonistas, ask not what our language can do for you, ask
> 
> what you can do for our language.
> 
> 
> 
> Mark Lawrence

Hello again. I forgot to tell you: I'm in Windows OS, Python 3.4.1, using tkinter.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web