http://qs321.pair.com?node_id=1212975

jsteng has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I am trying to make a customized TK::Listbox using TK::canvas because I need the ability to change text color and font when <double-1>
here is my initial work:
#!/usr/bin/perl use warnings; use strict; use Tk; my ($DimX,$DimY)=(400,600); my ($mX,$mY) = (2,2); my $mw = MainWindow->new( -bg=> "#000000", -borderwidth=> 0); $mw->minsize( $DimX, $DimY ); $mw->maxsize( $DimX, $DimY ); my %canvas; my $fontsize=int(20); $canvas{'canvas'} = $mw->Scrolled( 'Canvas', -width => $DimX-2*$mX, -height => 2*$DimY, -bg => '#60C8BC', -borderwidth => 2, -relief => 'raised', -scrollbars => 'e', )->pack(); $canvas{'canvas'}->CanvasBind("<Button-1>", [ \&print_xy, Ev('x'), Ev( +'y') ]); sub print_xy { my ($canv, $x, $y) = @_; my $sel = int($canvas{'canvas'}->canvasy($y) / (1.4*$fontsize+2)); printf "Selected: %d, (%d,%d)\n", $sel, $canvas{'canvas'}->canvasx +($x),$canvas{'canvas'}->canvasy($y); $canvas{'text'}{$sel}->itemconfigure( -fill => '#0000FF', -font => "Courier $fontsize bold", ); } for (my $y=0; $y<200; $y++) { $canvas{'text'}{$y} = $canvas{'canvas'}->createText( 5, 4+$y*(1.4* +$fontsize+2), -fill => '#000000', -text => "GgYy".$y x 20, -font => "Courier $fontsize normal", -anchor => 'nw', ); } MainLoop;
Problems:
1. I could not make the scrollbar scroll.
2. How do I change the selected item's font/color?
I tried doing this:
$canvas{'text'}{$sel}->itemconfigure( -fill => '#0000FF', -font => "Courier $fontsize bold", );
But it is not working.
3. lastly, how do I retrieve a particular selected text's font/color? Sorry folks, I am very rusty with perl after years of not programming.

Thanks BTW: My original (>10 years ago) script used TK::ROText; however in that version, the windows' size is fixed, and all entry in the ROText are space padded to cover the whole line (sprintf "%-50s", $text). Then using tag for each line. That was a nightmare, it was ugly programming. I am redoing that script to use Listbox; it was alot cleaner but I could not change font of selected text (line) thus I am redoing it with Canvas.