Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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!",); }

Comment on Tk won't output until finished
Download Code
Re: Tk won't output until finished
by Athanasius (Monsignor) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1015886]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2014-10-26 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (152 votes), past polls