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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |