That is exactly what you need to do. As I said before:

The key to using Tk is:

In this case:

Here's some very rough pseudocode.

# Create widgets. mw = create_main_window display = create_display(mw) # open the file we monitor. filehandle = open_file_for_monitoring('filename') # set up monitor mw->repeat( 1000, [monitor_file, filehandle, display ] ) # start main loop MainLoop sub monitor_file { new_text = <filehandle> display->insert('end', new_text) display->adjust_vertical_scroll }

It's very important to remember that the MainLoop is just a routine that looks something like:

sub MainLoop { while (1) { my $next_event = Get_Next_Event_From_Queue(); $next_event->execute; } }

So if your code takes a long time do ANYTHING, like it processes thousands of datapoints, reads large files, downloads a webpage or sleeps, then NO events will be processed, and the app will lock up.

Events are generated when you move the mouse, when you click, drag, move or resize widgets, on a scheduled basis, by subroutines. Any time you interact with the program, you are generating events. If you want your program to be responsive, it must be able to respond to any incoming events quickly.

The repeat you create works with the main loop by triggering an event at a scheduled interval. So if your repeat is set to do something every 10 seconds, at time = 10, it will generate an event that calls the subroutine you specified.

When you assign a subroutine to an event is is called "binding it to the event". So when a given event is triggered, your subroutine will be called. Until your routine returns, no other events can be processed, and the program will become unresponsive. That's why it is important to break your tasks up into very small, quickly executed chunks when working in an event driven environment like POE or Tk.

I hope this helps you to understand what exactly is going on in your Tk programs. Remember that you are not writing a script that proceeds in a straight line from start to stop. Instead you are setting up a system that must respond to events.


TGI says moo


In reply to Re^5: How can I get indefinite scroll to work in a TK text widget by TGI
in thread How can I get indefinite scroll to work in a TK text widget by padawan_linuxero

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.