Dear Monks:

I am working on a program to display the contents of a folder and this program needs to check every 5 seconds to folder and put the contents on a Listbox I am using Perl / Tk to do it graphic, yesteday asking about other problem they notice I was using a Sleep and as they told me Sleep does not go well with Tk, so they recommended to use Tk::After and after looking in my book "Mastering Perl/Tk" in Time Delays I saw Repeat which works ok, the thing is that my knowledge is limited and right now every time it runs the program, it creates a new Listbox every 5 seconds, how can I told the Listbox to list the data in the same Listbox instead of openinng a new Listbox every 5 seconds. Can you please help ? this is the code so far :
#!Perl $^W = 1; use strict; use File::Copy; use Date::Parse; use Date::Format; use Tk::DialogBox; use Tk::BrowseEntry; use Tk::ResizeButton; use Tk::ProgressBar; use Tk::LabFrame; use Tk::LabEntry; use Tk::ROText; use Tk::HList; use Cwd; use Tk; #Optional Modules# if ($^O eq 'MSWin32') { eval { require Win32::Console; Win32::Console::Free() }; if ($@) { warn "Win32::Console is not installed.\n$@"; } } #Declarations# my $VERSION = 2.7; my $loadhistory = 0; my $sort_cnt = 3; my ($ftp, $port, $after_id,); my $cwd = cwd; #Main# open STDERR, ">PFTPc.log" or warn "Cannot create PFTPc.log\a\n$!"; my $mw = MainWindow->new(-relief => 'raised', -bd => 2,); $mw->title("Asociacion de Agentes Aduanales de Matamoros --- Valida +cion Automatica"); $mw->geometry("1024x764+4+25"); my $respuesta; &user_input($mw); &create_dropdown($mw); &list_dir_enviar($mw); &list_dir_enviados($mw); &list_dir_respuesta($mw); $mw->Button(-text => "Salir", -command => sub { exit })->pack(-side => 'bottom'); &Tk::MainLoop(); ############################################################## sub list_dir_enviar { $mw->repeat(5000, \&refresh1); } ################################################################## sub list_dir_enviados { # my $mw = MainWindow->new; my $box1 = $mw->Listbox( -relief => 'sunken', -height => 5, -setgrid => 0, ); my @items1 = glob "c:/AAAvalida/valida/enviados/*.*"; #my @items = qw(One Two Three Four Five Six Seven Eight Nine Ten Eleve +n Twelve); foreach (@items1) { $box1->insert('end', $_); } my $scroll1 = $mw->Scrollbar(-command => ['yview', $box1]); $box1->configure(-yscrollcommand => ['set', $scroll1]); $box1->pack(-side => 'left', -fill => 'both', -expand => 1); $scroll1->pack(-side => 'right', -fill => 'y'); } ################################################################### sub list_dir_respuesta { # my $mw = MainWindow->new; my $box2 = $mw->Listbox( -relief => 'sunken', -height => 5, -setgrid => 0, ); my @items2 = glob "c:/AAAvalida/valida/respuestas/*.*"; #my @items = qw(One Two Three Four Five Six Seven Eight Nine Ten Eleve +n Twelve); foreach (@items2) { $box2->insert('end', $_); } my $scroll2 = $mw->Scrollbar(-command => ['yview', $box2]); $box2->configure(-yscrollcommand => ['set', $scroll2]); $box2->pack(-side => 'left', -fill => 'both', -expand => 1); $scroll2->pack(-side => 'right', -fill => 'y'); } ###################################################################### +### sub refresh1 { my $box = $mw->Listbox( -relief => 'sunken', -height => 5, -setgrid => 0, ); my @items = glob "c:/test/*.*"; #my @items = qw(One Two Three Four Five Six Seven Eight Nine Ten Eleve +n Twelve); foreach (@items) { $box->insert('end', $_); } my $scroll = $mw->Scrollbar(-command => ['yview', $box]); $box->configure(-yscrollcommand => ['set', $scroll]); $box->pack(-side => 'left', -fill => 'both', -expand => 1); $scroll->pack(-side => 'right', -fill => 'y'); } sub user_input { my $mother = shift; my $label_wert = $mw->Label( -text => 'Tu respuesta :', )->place( -x => 10, -y => 10); my $entry_wert = $mw->Entry( -width => 20, )->place( -x => 80, -y => 10); } sub create_dropdown { my $mother = shift; # Create dropdown and another element which shows my selection my $dropdown_value; my $dropdown = $mother->BrowseEntry( -label => "Label", -variable => \$dropdown_value, )->pack; my $showlabel = $mother->Label( -text => "nothing selected", )->pack; # Configure dropdown $dropdown->configure( # What to do when an entry iws selected -browsecmd => sub { $showlabel->configure(-text => "Ha seleccionado: $dropdown +_value" ), }, ); # Populate dropdown with values foreach ( qw/Enviados Recibido Errores/ ) { $dropdown->insert('end', $_); } # Set the initial value for the dropdown $dropdown_value = "Enviados"; }

In reply to Problem with Tk::Repeat by padawan_linuxero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.