sashac88 has asked for the wisdom of the Perl Monks concerning the following question:

Hello great monks!
Please take a look at the code below:
$tasks_dirs_list = $frame8->Scrolled('Listbox',-setgrid=>"1",-height=> +"12",-width=>80,-scrollbars=>"se"); $tasks_dirs_list->pack(-expand=>'yes',-fill=>'both',-padx=>20,-pady=>1 +0); $tasks_dirs_list->insert(0,@tasks);
I have a button that updates the @tasks array and I wish to be able to update the $tasks_dirs_list.
I used to destroy the $tasks_dirs_list and to recreate it again, but I know that it's possible to update $tasks_dirs_list without destroing.
Please let me know how to achieve what I want!
Thanks a lot!!!

Replies are listed 'Best First'.
Re: Perl Tk update widget
by zentara (Cardinal) on Jan 23, 2007 at 17:24 UTC
    Try this first:
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = Tk::MainWindow->new(-title => 'Listbox'); my @array = (1..10); my $lb = $mw->Scrolled('Listbox', -listvariable=> \@array, )->pack(); my $b = $mw->Button(-text => 'update', -command => \&update )->pack(); MainLoop; sub update { @array = map{"$_.a"}(1..10); push @array,11; $lb->update; }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Perl Tk update widget
by swampyankee (Parson) on Jan 23, 2007 at 16:45 UTC

    The key bit is here:

    $tasks_dirs_list->insert(0,@tasks);
    You can insert and delete from any point in the list, using the Tk::Listbox widget's insert and delete commands. Or you could try using listVariable, which is, according to the docs (I use ActiveState 5.8.8)"&hellip is only partially implemented in Perl/Tk:"

    emc

    Insisting on perfect safety is for people who don't have the balls to live in the real world.

    —Mary Shafer, NASA Dryden Flight Research Center