http://www.perlmonks.org?node_id=1015886

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

Sorry can't think of a better title!

I have the simple code below. When I pass a value to &check_card the $mw->label doesn't appear until the &check_in_SQLStore completes. This defeats the purpose!

I have even tried putting the label in it own function and calling that first (once card length >0) but it still waits for the next function to complete!

Autoflush to positive doesn't help and WaitBox seems a little ropy/difficult/OTT for what I need.

Could anyone suggest how I could make the "Please wait..." text appear while/before the check_in_SQLStore function executes?

#!/usr/bin/perl use strict; use warnings; use Tk; use DBI; my $mw = MainWindow->new; $mw->geometry("500x300+600+200"); my $text; $mw->title("Account Details"); $mw->Label( -text => "Card Number:" )->pack(-side => 'top'); my $card = $mw->Entry(-textvariable => '', -background => 'white', -width => 24)->pack(-side => 'top'); $mw->Button( -text => "Check Account", -command => \&check_card, )->pack(-side => 'top'); $mw->Button( -text => "Done", -command => sub {exit} )->pack(-side => 'top'); MainLoop; sub check_card { my $cardno = $card->get(); if(length $cardno =="0"){ error_no_card(); } elsif(length $cardno > "0") { $mw->Label(-text => "\nChecking Account Details for '$cardno'.\n Pleas +e Wait......\n", -width => 54)->pack(); } if(length $cardno > "0"){ my $exists = check_in_SQLStore($cardno); if($exists =="0"){ print "We got nothing\n"; } } } sub error_no_card { $mw->messageBox(-title => "Error!", -type=>'ok', -message => "Please e +nter an Account Card number!",); }

Replies are listed 'Best First'.
Re: Tk won't output until finished
by Athanasius (Archbishop) on Jan 29, 2013 at 15:55 UTC

    The following seems to work correctly:

    sub check_card { my $cardno = $card->get(); if (length $cardno == 0) { error_no_card(); } elsif (length $cardno > 0) { $mw->Label ( -text => "\nChecking Account Details for '$cardno'.\n Ple +ase Wait......\n", -width => 54, )->pack(); $mw->update; my $exists = check_in_SQLStore($cardno); print "We got nothing\n" unless $exists; } }

    That is, call $mw->update; immediately after creating the label.

    See, for example, the recent thread Perl/Tk window contents disappear when obscured then revealed.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,