$_[1] is initialized, as you passed a parameter to sub color(), which takes Ev('A') containing the value of the last key stroke.
"how can I accomplish what I want to do in this sub if I cannot use $_?"
Why cannot you? That's you code, and you can always modify it to work ;-) I believe that you expect $_ to contain (part of) the content in your text box. You can always call get() method of the text box to get the content at certain position or a range of positions.
Slightly modified your code to demo a little bit more: (Played with this code, and I do see some text colored blue. Hey, that's mainly your code!)
use Tk; use strict; use warnings; my $mw = new MainWindow(title => "demo"); my $entry = $mw->Scrolled("Text", -scrollbars => 'e', -font => '12')-> +pack(-side => 'bottom', -fill => 'both', -expand => 1); #$entry->bind("<KeyRelease>", [sub {print $_[1];}, Ev('A')]); $entry->bind("<KeyRelease>", [\&color, Ev('A')]); $entry->tagConfigure("blue", -foreground => "blue"); MainLoop; sub color { my $content = $entry->get("1.0", "end"); my $count = 0; my @char = split(//, $content); my @word = split(/ /, $content); foreach my $char (@char) { $count++; } foreach my $word (@word) { if ($word =~ /color/) { my $len = length($word); my $from = "1\.$count"; my $next = $from + $len; $entry->tagAdd("blue", $from, $next); } } }
You still have to do some work to implement your application logic, but I have already given you the right tool. Have fun!
In reply to Re: Re: Re: Tk Scrolled textbox, parse on input?
by pg
in thread Tk Scrolled textbox, parse on input?
by Elijah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |