jellisii2 has asked for the wisdom of the Perl Monks concerning the following question:
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 | |
|
Re: Tkx not updating progressbar as expected
by Anonymous Monk on Jul 20, 2009 at 20:17 UTC | |
by jellisii2 (Hermit) on Jul 27, 2009 at 18:52 UTC |