The basic problem is that while your program is busy importing the data, it cannot tell Tk to do updates to its windows.

The easiest solution if you can manage that is to spawn off a separate program to do the actual data import. That way, you can even create a way to do fully unattended data imports without a GUI.

Another way would be to spawn a thread which does the importing, but using Tk with threads is likely to cause you no end of fancy problems because the resources allocated to Tk in the main thread will (or will not) get shared or recreated in the spawned thread. The same likely holds true when forking a child process.

Another thing you could do is to modify your data import loop to look like this:

my $start_time = time(); # remember when we started my $progress; while (<$input_file>) { ... if (time - $start_time > 2) { # 2 seconds have passed $progress = create_progress_dialog(); Tk->update(); # I don't know if there is such a thing or wheth +er Tk needs it }; }; undef $progress; # hide progress dialog if we have one

Alternatively, you can try to use the Tk facilities like Tk->after():

use Time::HiRes qw(time); my $progress; my $popup = Tk->after( 2, sub { $progress = create_progress_dialog } ) +; my $last_poll = time(); while (<$input_file>) { # let Tk process its events every 0.1 seconds: if (time - $last_poll > 0.1) { Tk->process_one_event(); }; ... }; if ($progress) { undef $progress; }; undef $popup; # cancel our Tk->after() timeout

That way, Tk can also respond when the user clicks on a window or tries to minimize/move it.


In reply to Re: Showing pop-up window after x-seconds processing by Corion
in thread Showing pop-up window after x-seconds processing by fanticla

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.