Re: $button->modify_bg() delay?

On Fri, Apr 02, 2004 at 14:06:38 -0600, John Ello wrote:
Hi, I'm writing a program in Gtk2-perl where I'd like to change the
background color of a button several times if a user hits the wrong
button. It seems that ->modify_bg() doesn't take effect until the
called subroutine finishes though. Is there a way around this?  Below
is a test program where the button is changed to green, then red. I
only ever see the red.

Also, how can I get the default colors for the three different states,
so they can be reset back to normal?

Any help would be much appreciated, thanks.

It has nothing to do with perl. Just Gtk when appearance should change
registers somewhere, that the widget should be redrawn and actualy only
does it in the main loop. So you have to make at least one loop of

There are generaly two ways to do it: Call it recursively or register
a timer. Since you need an event to exit the recursive mainloop, you'd
need to set some timer up anyway -- so just register a timer to go off
after 5 sec and do the rest of work (anonymous closures come handy

As for reseting -- you'll have to look at the style stuff. But I never
needed to mess with it, so I won't tell you details.

By the way, it SHOULDN'T be POSSIBLE to hit a WRONG BUTTON. You should
make it insensitive (set_sensitive(0)) when hitting it does not make


use strict;
use Gtk2 -init;

my $window = Gtk2::Window->new( 'toplevel' );
my $button = Gtk2::Button->new( 'Push me' );

$button->signal_connect( 'clicked', \&clicked );
$window->add( $button );


sub clicked {
    my $green = Gtk2::Gdk::Color->parse( 'green' );
    my $red = Gtk2::Gdk::Color->parse( 'red' );

    $button->modify_bg( 'normal', $green );
    $button->modify_bg( 'active', $green );
    $button->modify_bg( 'prelight', $green );
    sleep 5;
    $button->modify_bg( 'normal', $red );
    $button->modify_bg( 'active', $red );
    $button->modify_bg( 'prelight', $red );
gtk-perl-list mailing list
gtk-perl-list gnome org

                                                 Jan 'Bulb' Hudec <bulb ucw cz>

Attachment: signature.asc
Description: Digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]