The main thing to remember with Tk (or any GUI coding), is that you start out by creating a bunch of widgets, then you start the program running and the widgets need to respond to things that happen (events). This model is referred to as 'event driven programming'. It's a bit different than writing console apps, and takes some getting used to.

Creating and destroying widgets in Tk leads to memory leakage. You need to keep your widgets around and reuse them instead of destroying them.

I noticed you had "use Tk::ProgressBar" in your example code. I've had big problems with memory leaks using ProgressBar widgets with Tk 804.027. YMMV.

I've hacked at your code a bit to make it work and refashion it a bit after my own style. There are things I'd still change (like naming things by purpose rather than 'Box_One'), but it works and should provide a good starting point.

#!Perl #$^W = 1; # is there a reason why you don't just use warnings? use strict; use warnings; use Tk; use Tk::BrowseEntry; use Cwd; use List::Util qw(shuffle); #Declarations# my $VERSION = 2.7; my $loadhistory = 0; my $sort_cnt = 3; my ($ftp, $port, $after_id,); my $cwd = cwd; my $mw = MainWindow->new( -relief => 'raised', -bd => 2, ); $mw->title("Asociacion de Agentes Aduanales de Matamoros --- Validacio +n Automatica"); $mw->geometry("1024x764+4+25"); # Make all your widget groups my $entry = Build_User_Entry($mw); my $dd = Build_Dropdown($mw); my $box1 = Build_Listbox_One($mw); my $box2 = Build_Listbox_Two($mw); my $button = Build_Exit_Button($mw); # Lay them out - use only one geometry manager per containing frame. $entry->grid( -columnspan => 2 ); $dd->grid( -columnspan => 2 ); $box1->grid( $box2 ); $button->grid( -columnspan => 2 ); # Start monitoring my ($enviados, $respuestas) = Start_Directory_Monitors( $mw, $box1, $b +ox2 ); MainLoop(); ################################################### # Build widgets sub Build_User_Entry { my $mw = shift; my $f = $mw->Frame(); my $label_wert = $f->Label( -text => 'Tu respuesta :', )->pack( -side => 'left', ); my $entry_wert = $f->Entry( -width => 20, )->pack( -expand => 1, -fill => 'y', ); return $f; } sub Build_Dropdown { my $mw = shift; my $f = $mw->Frame(); my $label_text = "nothing selected"; my $dropdown_value; my $showlabel = $f->Label( -textvariable => \$label_text, ); my $dropdown = $f->BrowseEntry( -label => "Label", -variable => \$dropdown_value, -browsecmd => sub { $label_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"; $showlabel->pack; $dropdown->pack; return $f; } sub Build_Listbox_One { my $mw = shift; my $box1 = $mw->Scrolled( 'Listbox', -scrollbars => 'e', -relief => 'sunken', -height => 5, -setgrid => 0, ); return $box1; } sub Build_Listbox_Two { my $mw = shift; my $box2 = $mw->Scrolled( 'Listbox', -scrollbars => 'e', -relief => 'sunken', -height => 5, -setgrid => 0, ); return $box2; } sub Build_Exit_Button { my $mw = shift; my $button = $mw->Button( -text => "Salir", -command => sub { exit }, ); return $button; } ############################################################## sub Start_Directory_Monitors { my $mw = shift; my $enviados_display = shift; my $respuesta_display = shift; my $env = $mw->repeat(5000, [ \&list_dir_enviados, $enviados_disp +lay ] ); my $res = $mw->repeat(5000, [ \&list_dir_respuesta, $respuesta_dis +play ] ); return $env, $res; } # monitor enviados sub list_dir_enviados { my $box = shift; $box->delete(0,'end'); # empty listbox #my @items = glob "c:/AAAvalida/valida/enviados/*.*"; my @items = shuffle qw(One Two Three Four Five Six Seven Eight Nin +e Ten Eleven Twelve); foreach (@items) { $box1->insert('end', $_); } } # monitor respuestas sub list_dir_respuesta { my $box = shift; $box->delete(0,'end'); # empty listbox #my @items = glob "c:/AAAvalida/valida/respuestas/*.*"; my @items = shuffle qw(One Two Three Four Five Six Seven Eight Nin +e Ten Eleven Twelve); foreach (@items) { $box->insert('end', $_); } } ###################################################################### +###


TGI says moo


In reply to Re: Problem with Tk::Repeat by TGI
in thread 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.