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

Dear Monks,
when tk program running if i switch to another window and come back to tk window the screen is complete white.
why this is happening ?
how to make normal when i switch back for one window to tk running window

Replies are listed 'Best First'.
Re: TK screen problem
by Sandy (Curate) on Oct 31, 2008 at 14:37 UTC
    If your Tk program is busy doing stuff when you switch to and from another window, then the Tk image will not be re-drawn.

    So, as anon suggested, pepper your code with $mw->update() in long loops, or processing sections etc.

    For efficiency sake (i.e. don't slow down your program) do NOT

    foreach my $i (1..10000) { ... do stuff $mw->update(); }
    instead, only update sometimes (every 100 iterations perhaps?)
    foreach my $i (1..10000) { ... do stuff if (int($i/100)*100 == $i) { $mw->update(); } }
      if (int($i/100)*100 == $i) {
      That can be more concisely written as if ($i % 100 == 0) {

        Or:

        unless ($i % 100) {

        :P

        I'm so adjective, I verb nouns!

        chomp; # nom nom nom

Re: TK screen problem
by zentara (Cardinal) on Oct 31, 2008 at 20:28 UTC
    The advice to use "mw->update;" sprinkled everywhere indicates a bad Tk program design. You are blocking the eventloop somewhere, and you can probably write your code differently to avoid the problem. You need to show all your code, or a smaller version that demonstrates the problem.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: TK screen problem
by Anonymous Monk on Oct 31, 2008 at 14:19 UTC
    Bug in your code or bug in tk, try $mw->update