locked_user mr_leisure has asked for the wisdom of the Perl Monks concerning the following question:
#!/sbcimp/run/pkgs/gsbl/bin/perl -w #!/sbclocal/bin/perl -w #use strict; use Tk; # open filehandle open (LOG, "commandpost.log") || die "Could not open file : $!\n"; ##### # # Main Window # ##### my $mw = MainWindow->new(); # add label $mw->Label(-text => "CMD_POST Error Catcher")->pack; ##### # # Menubar # ##### my $menubar = $mw->Frame(-relief => "ridge", -borderwidth => 2)->pack (-anchor => "nw", -fill => "x"); # add file option to menubar my $filemenu = $menubar->Menubutton(-text => "File", -underline => 1)->pack (-side => "left"); # add separator $filemenu->separator(); # add help menu my $helpmenu = $menubar->Menubutton(-text => "Help", -underline => 1)->pack (-side => "left"); # add separator $helpmenu->separator(); # add about option $helpmenu->command(-label => "About...", -underline =>1, -command => \&help_about); ##### # # Main Text Box # ##### my $listbox = $mw->Listbox(-relief => "sunken", -width => 170, -height + =>30, -background => "white"); # scrollbar my $scrollbar = $mw->Scrollbar(-command => ["yview", $listbox]); $listbox->configure(-yscrollcommand => ["set", $scrollbar]); # set listbox internal colour $listbox->configure(-background => "LightBlue2"); # set main window colour $listbox->setPalette("LightBlue1"); $listbox->pack(-side => "left", -fill => "both", -expand => "yes"); $scrollbar->pack(-side => "right", -fill => "y"); # loop and subroutine to enter text from logfile into listbox $mw->fileevent(LOG, 'readable', [\&insert_lines]); MainLoop; ##### # # Subroutines # ##### sub insert_lines { my $logline; if ($logline =<LOG>) { $listbox->insert('end', $logline); $listbox->yview('moveto' +,100); #format_text(); } else { $mw->fileevent(LOG, 'readable +', ""); } }
So i figure this bit of code will do the trick. Alas, but no. All that happens is now I get a blank listbox. I thought by putting it before $mw->fileevent(LOG, 'readable', [\&insert_lines]); I wouldn't be screwing up the loop that reads the text file.my $textline; while ($textline = <LOG>) { if ($textline =~ /CRITICAL/) { $listbox->configure(-foreground => "red2"); } elsif ($textline =~ /MAJOR/) { $listbox->configure(-foreground => "DarkOrange2"); } else { } } $mw->fileevent(LOG, 'readable', [\&insert_lines]);
this is still not finishedif ($mr_leisure) { bow; }
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TK Problem (me again)
by danger (Priest) on Jan 05, 2001 at 01:38 UTC | |
|
Re: TK Problem (me again)
by OeufMayo (Curate) on Jan 05, 2001 at 01:36 UTC | |
|
Re: TK Problem (me again)
by ichimunki (Priest) on Jan 04, 2001 at 23:46 UTC | |
|
Re: TK Problem (me again)
by chipmunk (Parson) on Jan 05, 2001 at 01:04 UTC | |
|
(tye)Re: TK Problem (me again)
by tye (Sage) on Jan 04, 2001 at 23:05 UTC | |
|