the main window freezes until the all the directories have been parsed.

Well think about it, the program's execution pointer is busy devoting full time to parsing the directories, so the window-gui seems to lock up. This is one of the most common problems faced when doing GUI's, so don't feel bad.

There are many solutions. The simplest solution is to liberally sprinkle "$mw->update" throughout your directory parsing sub, like:

# get info from dictionary files while(($folder, $drive) = each %search_locations) { #get list of files in directory $mw->update; $var = "Looking in - $drive/DICT/SOURCE\n"; chdir "$drive/variable/DICT/SOURCE"; $mw->update; @file_list = glob ("*.dsf"); $mw->update; $var = “Num of files: $#file_list”; }
That may be excessive, but everytime you call $mw->update, your gui will get some processor time.

The other options involve forking off your dir-processing and using Tk::fillevent to read the results, in a non-blocking manner. You can also do the same thing with threads.

So it depends how how much time passes in the lines between each $mw->update. If they are on your local machine, it's probably fast, but if it's over a network link, it may be slow. So then you may have to use fileevent, forks and/or threads. Generally in a GUI, you never use "while(1)" or "sleep", because it blocks the gui.

Your problem is usually called "blocking the gui", and you can google for "Tk non blocking" to see the myriad of situations and solutions, people have used talked about, regarding blocking the gui.


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

In reply to Re: Newbie with a TK question by zentara
in thread Newbie with a TK question by hebes_99

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.