×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

TK - How to update Window automatically

TK - How to update Window automatically

TK - How to update Window automatically

(OP)
Hi everyone,

I'm trying to write a little "graphical" print queue monitor that's supposed to count the number of files in a certain directory and draw a line according to the number of files.

So far I managed to write a little window that draws the line as intended, but only once ...

How do I get the window to update automatically every few seconds ?

CODE

#!/usr/bin/perl -w

use strict;
use Tk;

my $window= MainWindow->new;
my $c1 = $window->Canvas(-background => 'saddlebrown', -width => '350', -height => '150')->pack;

$c1->createText(175, 10, -fill => 'orange', -text => 'Print Queue Monitor');
$c1->createLine(0, 20, 351, 20, -fill => 'orange');

my $jobs01=`ls -all | wc -l | awk \'{print \$1}\'`;
chomp ($jobs01);
$jobs01 +=88;

$c1->createLine(88, 65, $jobs01, 65, -width => '10', -fill => 'green');
$c1->createText(45, 65, -fill => 'orange', -text => 'Spooler Queue');
MainLoop; 

Any ideas ?

Best Regards,
Thomas

RE: TK - How to update Window automatically

Put the line which draws the line inside a while loop, and sleep ?

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments winky smile

RE: TK - How to update Window automatically

Look at perldoc Tk::after. You can set up a callback to draw the line every few seconds in a subroutine.

CODE

my $id = $c1->repeat( 2500, \&draw_line );
MainLoop;

sub draw_line
  {
  # put the line drawing code here
  } 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close