unknown-monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
first of all sorry, but I didn't know a better title.
#!/usr/bin/perl -w use Tk; my $mw =MainWindow ->new; $mw -> title ("Untitled"); $mw -> Button(-text => "S H O W", -command => \&show)->grid(-row => 0, + -column => 0); $mw -> Button(-text => "E X I T", -command => sub {exit})->grid(-row = +> 0, -column => 1); $lb2 = $mw -> Scrolled('Listbox', -width=> 30, -height => 10, -selectm +ode => "single", -scrollbars => 'e', -setgrid =>1, -background => 'bl +ack', -foreground => 'white') -> grid (-row => 1, -column => 0); MainLoop; sub show { $lb2 -> delete(0,'end'); open(PIPE, "du -a 2>&1 |") or die "Could not open pipe: $!\n" ; while (<PIPE>) { chop ($_) ; $lb2 -> insert('end',$_); } close(PIPE) ; } exit (0);
When I push the SHOW button, it's relief stays sunken and the listbox (lb2) empty.
After the while loop has finished, the button's relief is restored to its original value and the listbox is filled with data.

What needs to be changed, so the listbox gets filled "live"?
I guess the button needs to be forced to change it's state/get released?

Regards,
unknown-monk

Replies are listed 'Best First'.
Re: perl/Tk: How to "release" a button immediately after it's pushed?
by almut (Canon) on Apr 27, 2010 at 14:12 UTC
    What needs to be changed, so the listbox gets filled "live"?

    You could add an $lb2->update() in the long running while loop

    while (<PIPE>) { chop ($_) ; $lb2 -> insert('end',$_); $lb2->update(); # <--- }
      Thank you *very* much! That solved my problem.

      Kind regards,
      unknown-monk
Re: perl/Tk: How to "release" a button immediately after it's pushed?
by roboticus (Chancellor) on Apr 27, 2010 at 14:16 UTC

    unknown-monk

    The problem appears to be that you're holding up the GUI thread. You need to return ASAP from your event routines. If you have anything that takes a significant amount of time, run it in a different thread. It's a frequently-encountered issue, so google and/or super search will help you find some specific examples.

    ...roboticus