Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TK - How to update Window automatically

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
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
 
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 ;-)
 
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
  }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top