#! /usr/local/bin/perl -w
require 5.005;
use strict;
use English;
use Tk;
# Create main window with button and text widget in it...
my $top = MainWindow->new;
my $btn = $top->Button(-text=>'print odd lines')->pack;
my $txt = $top->Scrolled('Text', -relief=>'sunken', -borderwidth=>'2',
-setgrid=>'true', -height=>'30', -scrollbars=>'e');
$txt->pack(-expand=>'yes', -fill=>'both');
$btn->configure(-command=>sub{&GetText($txt)} );
# Populate text widget with lines tagged odd and even...
my $lno;
my $oddeven;
foreach $lno (1..20) {
if($lno % 2) { $oddeven = "odd" } else { $oddeven = "even" };
$lno = "Line $lno ($oddeven)\n";
$txt->insert ('end', $lno, $oddeven);
}
# Do the main processing loop...
MainLoop();
sub GetText {
my $txtobj = shift;
$txtobj->tag('configure', 'odd', -background=>'lightblue');
$txtobj->tag('configure', 'even', -background=>'lightgreen');
# This is the goal of all the work...
my @lines = $txtobj->get($txtobj->tagRanges('odd'));
print STDERR join("", @lines);
}