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

I suspect this is a lack of understanding the underlying issue, but my google-fu is failing me.

I am in the process of writing a Tkx based program. At one point in this program I have to iterate through a list of files to do stuff with them. I want to provide the user visual feedback about how far along the list I am when I am iterating through the files.

The thing is that when I attempt to update my progress bar inside the iteration loop, the gui doesn't change.

I suspect the problem is a threading issue, where I'm not setting up my UI in a separate thread or something to that effect. Thing is that, if that is the problem, I can't find any documentation or howto for dummies to do it.

This is not complete code, but I think it's enough to get the idea of what I'm doing across.

use strict; use XML::Twig; use Tkx; use Net::FTP; use Thread; # needed for frames and grids to work. Tkx::package_require("tile"); # main window and properties my $main_window = Tkx::widget->new("."); my $grid = $main_window->new_ttk__frame( # left going clockwise -padding => "1 1 1 1", -borderwidth => 5, ); $grid->g_grid( -column => 0, -row => 0, -sticky => "nsew", ); $main_window->g_grid_columnconfigure( 0, -weight => 1, ); $main_window->g_grid_rowconfigure( 0, -weight => 1, ); &init(); Tkx::MainLoop(); sub init { # Progress bar... my $progress = 0; my $overall_progress_bar = $grid->new_ttk__progressbar( -orient => "horizontal", -mode => "determinate", -length => "200", -maximum => $file_count, -value => $progress, ); # buttons... my $publish = $grid->new_button( -text => "Publish", -command => sub { # now for heavy lifting... # get a list of files to be FTPed. my @ftp_list = &get_ftp_list($chosen_dir); # get a count of how many files I'm FTPing. my $file_count = scalar(@ftp_list); # get the media ID of the capture my $media_id = &check_media_id($chosen_dir); $overall_progress_bar->configure(-maximum => $file_count); # FTP the files, and count the number of successes. foreach my $i (@ftp_list) { $progress++; my $result = &ftp_file($i, $media_id, @profile_info); if ($result == 200) { $progress++; } } }, ); # layout section $choose_dir_label->g_grid(-column => 0, -row => 0, -columnspan => +2); $choose_dir->g_grid(-column => 2, -row => 0, -columnspan => 2); $chosen_dir_label->g_grid(-column => 0, -row => 1, -columnspan => +4); $profile_list_label->g_grid(-column => 0, -row => 2); $profile_list->g_grid(-column => 1, -row => 2, -columnspan => 2); $profile_info_label->g_grid(-column => 0, -row => 3, -columnspan = +> 4); $publish->g_grid(-column =>0, -row => 4); $modify_settings->g_grid(-column => 1, -row => 4); $reset->g_grid(-column => 2, -row => 4); $exit->g_grid(-column => 3, -row => 4); $overall_progress_bar->g_grid(-column => 0, -row => 5, -columnspan + => 4); &layout($grid); } sub layout { # Grabs a list of the current elements on the grid and adds 2px pa +dding # on every side of each element. foreach (Tkx::SplitList($_[0]->g_winfo_children)) { Tkx::grid_configure($_, -padx => 2, -pady => 2); } }

Replies are listed 'Best First'.
Re: Tkx not updating progressbar as expected
by Argel (Prior) on Jul 20, 2009 at 19:48 UTC
    I have only used Tk so I'm not sure how well this applies. But I do have a Perl/Tk app that pings hosts and dumps the results into a window. It's not really interactive at that point but the user can see the progress. I know it's not Tkx but I hope this might help give you some ideas.
    # Including this to show where the widgets are created. sub gui { # ... $tk{top} = MainWindow->new(); $tk{nb} = $tk{top}->NoteBook()->pack( -fill=>'both', -expand=>1 ); $tk{p2} = $tk{nb}->add( 'page2', -label => 'Status' ); ( $tk{stat} ) = $tk{p2}->Scrolled( 'ROText', -wrap => 'none', -scr +ollbars => 'se' ); #... } #The yviewMoveto() and update() calls update the notebook page. sub myprint { my( $msg ) = @_; $tk{stat}->insert( 'end', $msg ); $tk{stat}->yviewMoveto( 1 ); $tk{stat}->update(); } # Just showing how myprint() gets called sub start_pinging_button_was_clicked { # ... $tk{stat}->Busy( -recurse => 1 ); foreach my $host ( @data ) { my $result = myping($host); myprint( $result ); $tk{stat}->Unbusy(); # ... }

    Elda Taluta; Sarks Sark; Ark Arks

Re: Tkx not updating progressbar as expected
by Anonymous Monk on Jul 20, 2009 at 20:17 UTC
    You'll have to call DoOneEvent
    $Tkx::TRACE=64; # at top of your program $progress++; Tkx::i::DoOneEvent(0); # allow gui to update
      Thanks for this. I'm not using it, but it set me on the right path to find Tkx::update().

      EDIT: Nevermind, discovered that I'm not as smart as I thought I was.