Posted to tcl by patthoyts at Mon Sep 04 13:05:26 GMT 2006view raw

  1. # Sample perl/tk to load self into a scrolled text widget
  2. #
  3. use strict;
  4. use Tk;
  5.  
  6. my $cw = Tk::MainWindow->new(-title => 'Perl/Tk Sample');
  7. my $txt = $cw->Scrolled("Text", -scrollbars => 'se')
  8. ->pack(-expand => 'both', -pady => '2');
  9.  
  10. $txt->tagConfigure('comment', -foreground=>'red');
  11.  
  12. open(FH, $::0) || die "failed $!";
  13. while (<FH>) {
  14. my $tag = '';
  15. $tag = 'comment' if (/^#/);
  16. $txt->insert('end', $_, $tag);
  17. $tag = '';
  18. }
  19. close FH;
  20.  
  21. Tk::MainLoop;
  22.