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

Hi monks, I have a main window update question. I have a simple but long script that runs as a subroutine when the user makes some selections in the main window. I'm having an update issue with the progress bar. I tried using fork by I got an error due to an line using SMTP in the subroutine. I'm thinking fork may not be he best solution and that I'm missing something. Here's a stripped down example of my code:

use strict; use warnings; #use Mozilla::CA; use Tkx; use Tcl::Tk; #set window geometry and options my $mw = Tkx::widget->new("."); $mw->g_wm_minsize(400, 500); $mw->g_wm_title(my $title); my $b; $b = $mw->new_button( -text => "Run", -command => \&run, #); #Tkx::after(500, sub { $mw->g_destroy }); #}, ); $b->g_pack( -padx => 10, -pady => 10, ); #Quit button my $b2; $b2 = $mw->new_button( -text => "Quit", -command => sub { $b2->m_configure( -text => "Quit", ); CORE::exit; Tkx::after(500, sub { $mw->g_destroy }); }, ); $b2->g_pack( -padx => 10, -pady => 10, ); #Table Output Tkx::package_require("Tktable"); $mw = Tkx::widget->new("."); my $t = $mw->new_table( -rows => 5, -cols => 3, ); $t->g_pack; #Progress Bar my $progress = "10"; my $overall_progress_bar = $mw->new_ttk__progressbar( -orient => "horizontal", -mode => "determinate", -length => "100", #-maximum => $file_count, #-value => $progress, -maximum => "400", -value => $progress, ); $overall_progress_bar->g_pack; Tkx::MainLoop(); exit; sub run { #First block of code #define links my $keywordsfile="keywords.txt"; ##a lot more happens here print "Test!!"; }

I've tried adding to the $progressbar value as well and using Tkx::update(); with no luck. Any guidance for this novice would be greatly appreciate. Another thing that I've seen that I'd like to fix is the main window, when I run on a PC, is unresponsive. I know it's all the same issue. Thank you

Replies are listed 'Best First'.
Re: Can't get progress bar or main window to update using Tkx
by Anonymous Monk on Feb 26, 2017 at 00:58 UTC

    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

      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

      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,