I want to be able to print text to a text widget immediately. So in the below code example, what ends up happening is both text items get printed after the sleep. I want the print that occurs before the sleep to actually happen, then sleep, then print what's after the sleep. Do I need to utilize fileevent for this? Can someone give me an example on how to do this? Many thanks!
use Tk; $mw = new MainWindow; $mw->title("Test"); $mw->Label(-text => "Pick an item from the list")->pack; $frm_versions=$mw->Frame()->pack; $list=$frm_versions->Listbox(-selectmode=>'single', -width=>0, -height +=>0); $list->pack; $list->insert('end', 'Text', 'MoreText', 'TextityTextText', 'TextyText +alicious', 'Textathon'); $textarea=$mw->Frame()->pack; $txt=$textarea->Scrolled("Text", -scrollbars=>'e', -width=>45, -height +=>10); $txt->pack; $mw->Button(-text => "GO!!!!", -command => \&go)->pack(-side => 'botto +m', -expand => 1, -fill => 'x'); MainLoop(); sub go{ $listselection=$list->curselection(); if ($listselection eq "") { $todo = ""; }else { $todo=$list->get($listselection); } $txt -> delete('0.0', 'end'); if ($todo){ $txt -> insert('end',"Let's see what you picked...\n\n\n"); sleep (2); $txt -> insert('end',"You picked $todo...\n"); }else{ $txt->insert('end',"Please pick something from the list...\n"); last; } }

In reply to Unbuffered printing to tk text widget by banango

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.