Monks, I'm sure there is a simple answer to this but I'm very new to perl and might have seen the answer and not even known it. What I'm trying to do is write a Tk program that displays the contents of a file that contains some meterological data. That part I've gotten down, the problem I'm having is that this file is updated every 5 minutes and I haven't figured out how to refresh the entry widgets. Here is the what I've done so far, any help, comments, or general remarks regarding this will be greatly appreciated.
#!\Perl\bin -w use Tk; $statfile = "c:\\data\\test.txt"; print "BEFORE WHILE\n"; open (FILE, $statfile) || die "Couldn't open file: $!"; my @statarray = <FILE>; foreach (@statarray){chomp;} #####Create Main GUI WINDOW###### my $main = MainWindow->new(); $main->title("FLOWINFO - Port Freeport Real-Time Navigation System"); #####BEGIN MENUBAR CREATION###### my $menu_bar = $main->Frame(-relief => 'groove', -borderwidth => 3)->p +ack(-side=>'top', -fill => 'x'); my $file_mb = $menu_bar->Menubutton(-text => 'File')->pack(-side=>'lef +t'); $file_mb->command(-label => 'Exit', -command => sub{$main->destroy}); my $help_mb = $menu_bar->Menubutton(-text => 'Help')->pack(-side => 'r +ight'); $help_mb->command(-label=>'About', -command =>\&about); $help_mb->command(-label=>'Help', -command =>\&help); ####BEGIN BUILDING GUI BODY######## my $top = $main -> Frame -> pack(-side=>'top', -fill =>'x'); my $left1 = $top -> Frame -> pack(-side =>'left',-pady =>9, -padx => 8 +); ##############MET############################## my $metlabel = $left1 -> Label(-text => ' METEORLOGICAL SENSORS')->pac +k(); $metsensor= $left1->Label(-text =>' Wind Speed ')->pack(); $metsensor= $left1->Label(-text =>' Wind Direction ')->pack(); $metsensor= $left1->Label(-text =>' Air Temperature ')->pack(); $metsensor= $left1->Label(-text =>' Barometric Pressure ')->pack(); $metsensor= $left1->Label(-text =>' Average Gust ')->pack(); my $left2 = $top -> Frame ->pack(-side=>'left',-pady => 2, -padx => 15 +); my $metstatlabel = $left2->Label(-text => 'METEORLOGICAL MEASUREMENTS' +)->pack(); #############ADCP############################## my $right1 = $top -> Frame ->pack(-side=>'right', -pady => 2, -padx=>1 +5); my $adcpstatlabel = $right1->Label(-text => 'ADCP MEASUREMENTS')->pack +(); my $right2 = $top ->Frame ->pack(-side=>'right'); my $adcplabel = $right2->Label(-text => 'ADCP SENSORS')->pack(); $adcpsensor = $right2->Label(-text => 'Drift')->pack(); $adcpsensor = $right2->Label(-text => 'Set')->pack(); $adcpsensor = $right2->Label(-text => 'Water Depth')->pack(); $adcpsensor = $right2->Label(-text => 'Water Temperature')->pack(); close FILE; print "closed File\n"; $main->bind("<Alt-F4>" => sub{exit}); print "Updating Array\n"; $main->repeat( 20000 => \&array_update); MainLoop(); sub array_update { open (FILE, $statfile) || die "Couldn't open file: $!"; my @statarray = <FILE>; close FILE; foreach (@statarray){chomp;} $metstat1->destroy() if Tk::Exists($metstat1); $metstat2->destroy() if Tk::Exists($metstat1); $metstat3->destroy() if Tk::Exists($metstat1); $metstat4->destroy() if Tk::Exists($metstat1); $metstat5->destroy() if Tk::Exists($metstat1); $adcpstat1->destroy() if Tk::Exists(adcpstat1); $adcpstat2->destroy() if Tk::Exists(adcpstat1); $adcpstat3->destroy() if Tk::Exists(adcpstat1); $adcpstat4->destroy() if Tk::Exists(adcpstat1); $metstat1 = $left2->Entry(-width => 5, -textvariable => \$statarray[0] +, -relief => 'sunken')->pack(); $metstat2 = $left2->Entry(-width => 5, -textvariable => \$statarray[1] +, -relief => 'sunken')->pack(); $metstat3 = $left2->Entry(-width => 5, -textvariable => \$statarray[2] +, -relief => 'sunken')->pack(); $metstat4 = $left2->Entry(-width => 5, -textvariable => \$statarray[3] +, -relief => 'sunken')->pack(); $metstat5 = $left2->Entry(-width => 5, -textvariable => \$statarray[4] +, -relief => 'sunken')->pack(); $adcpstat1 = $right1->Entry(-width => 5, -textvariable => \$statarray[ +5], -relief =>'sunken')->pack(); $adcpstat2 = $right1->Entry(-width => 5, -textvariable => \$statarray[ +6], -relief =>'sunken')->pack(); $adcpstat3 = $right1->Entry(-width => 5, -textvariable => \$statarray[ +7], -relief =>'sunken')->pack(); $adcpstat4 = $right1->Entry(-width => 5, -textvariable => \$statarray[ +8], -relief =>'sunken')->pack(); }

In reply to Problem refreshing TK window after file update by CorpusDawg

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.