Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Tk::Text insert buffer!

by Alle (Novice)
on Sep 26, 2012 at 11:27 UTC ( #995745=perlquestion: print w/ replies, xml ) Need Help??
Alle has asked for the wisdom of the Perl Monks concerning the following question:

Hi,Monks!

Tk::Text's insert method alwarys buffer my insert string,There's has a demo:

#!/usr/bin/perl -w use strict; use Tk; $| = 1; my $mw = MainWindow->new; my $text = $mw->Text->pack; my $bt = $mw->Button(-text => 'insert', -command => sub {&test_insert})->pack; MainLoop; sub test_insert{ for (1..3){ $text->insert('end', "$_\n"); sleep 1; } }

When I click insert button, the program will wait 3 seconds, then display 1 2 3,. although i set '$| = 1'.I don't want buffer the insert string. I want immediately display insert string every times! Please give me some tips ,thank you!

My Os is windows 7 64bit

Comment on Tk::Text insert buffer!
Download Code
Re: Tk::Text insert buffer!
by zentara (Archbishop) on Sep 26, 2012 at 11:53 UTC
    One of the rules of eventloop driven GUI's is NEVER USE SLEEP! Removing the sleep1 line, and it will work fine. If you need a delay, use Tk::after or Tk::repeat.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Thank you. I catch your mind, this is just a demo. I need display info on text widget immediately after insert method,no buffer,not wait 3 seconds and then display whole info. Can I?

        I need display info on text widget immediately after insert method,no buffer,not wait 3 seconds and then display whole info. Can I?

        Hi, sure you can. Using your example without the sleep statement:

        #!/usr/bin/perl -w use strict; use Tk; $| = 1; my $mw = MainWindow->new; my $text = $mw->Text->pack; my $bt = $mw->Button(-text => 'insert', -command => sub {&test_insert})->pack; MainLoop; sub test_insert{ for (1..3){ $text->insert('end', "$_\n"); } }
        or you may not be showing the real code you need to use. If you are trying to display something from some other source, and the Text widget isn't displaying it right away, you can try putting a "$mw->update" or a "$text->update" right after your insert statement. This timer may be what you are looking for, otherwise explain in greater detail what you are actually trying to display.
        #!/usr/bin/perl -w use strict; use Tk; $| = 1; my $mw = MainWindow->new; my $text = $mw->Text->pack; my $repeater = $mw->repeat(1000, \&test_insert); MainLoop; sub test_insert{ $text->insert('end', time."\n"); }

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-09-30 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (378 votes), past polls