I would also suggest using a class to encapsulate all computations with all its internal variables like y which get updated whenever something is done internally and are never exposed. The class could have a stop() method which will interrupt any loops via a stop-flag for example.

Passing a ref to a method in the class, e.g. in

my $plot = $mw->Button(-text=>'Plot', -command=>\&init) ->pack(-side=>'left');

can be done like:

my $computator = Computator->new($p, $mw, whatever ...); $computator->reset(); my $plot = $mw->Button(-text=>'Plot', -command=>sub { $computator->ini +t()} ) ->pack(-side=>'left'); # create a stop-button my $stop = $mw->Button(-text=>'Stop', -command=>sub { $computator->sto +p()}) ->pack(-side=>'left');

Warning, my Tk skills are minimal.

What I do not like is that the side-effect of the long computation seems to go away when you break the long computation in a lot of per-row computations. But this is very subjective to given photo size, host computer speed, Tk internals.

Can you not tell Tk to process event queue every time you complete the innermost loop? So as to have long loops without Tk becoming unresponsive?

If that fails, spawning a thread to do the long computation sounds to me like a good idea but it's tricky and it may open a can of worms, as per Perl Tk and Threads


In reply to Re: long computation in TK by bliako
in thread long computation in TK by BillKSmith

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.