Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Tk won't output until finished

by packetstormer (Monk)
on Jan 29, 2013 at 15:04 UTC ( #1015886=perlquestion: print w/replies, xml ) Need Help??
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 (Chancellor) 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,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1015886]
Approved by Athanasius
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2018-02-20 00:41 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (266 votes). Check out past polls.