in reply to Can't get progress bar or main window to update using Tkx

Hello again monks. So I worked a bit more on my problem and used a few examples here to put the following script together. My question is again why doesn't up update? The $progress value doesn't get passed and printed until I close the script and I don't understand why. Fork could work but I'm not sure if that's the right way to go. Any guidance is greatly appreciated. Here's my code:

use strict; use XML::Twig; use Tkx; use Net::FTP; use Thread; $Tkx::TRACE=64; my $file_count=200; my $progress =100; # 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 => 400, -value => $progress, ); # buttons... my $publish = $grid->new_button( -text => "Publish", -command => sub { # now for heavy lifting... # get a list of files to be FTPed. print $progress; $progress=$progress+100; Tkx::i::DoOneEvent(0); # allow gu +i to update #print $progress; #Tkx::update(); }, ); # layout section $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); } }

Thanks in advance for the guidance/assistance

Replies are listed 'Best First'.
Re^2: Can't get progress bar or main window to update using Tkx
by huck (Prior) on Feb 26, 2017 at 03:22 UTC

    use strict; #use XML::Twig; use Tkx; use Net::FTP; use Thread; $Tkx::TRACE=64; ############################ $|=1; ############################ my $file_count=200; my $progress =100; # 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 => 400, ############################ -variable => \$progress, ############################ ); # buttons... my $publish = $grid->new_button( -text => "Publish", -command => sub { # now for heavy lifting... # get a list of files to be FTPed. print $progress; $progress=$progress+100; ############################ # either of these seems to work Tkx::i::DoOneEvent(0); # allow gui to update #Tkx::update('idletasks'); ############################ #print $progress; #Tkx::update(); }, ); # layout section $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); } }
    for the printing $|=1; At first i thought it was Tkx::update('idletasks'); rather than Tkx::i::DoOneEvent(0); but in the end it was -variable => rather than -value

Re^2: Can't get progress bar or main window to update using Tkx
by beech (Parson) on Feb 26, 2017 at 03:25 UTC

    Hi,

    What connects the variable $progress to $overall_progress_bar?

    I don't thik "value" option does it, I think you have to use something else, maybe "variable"

    Try  -variable => \$progress, instead of -value   => $progress,