Dear Monks,
I have a problem with text widget: if the text widget does not have the focus, the selection tag is not visible.
That is annoying, if I use the built in Find function: founded parts are not selected.
How can I change this?
use Tk;
$mw = MainWindow->new;
# Create necessary widgets
$f = $mw->Frame->pack(-side => 'top', -fill => 'x');
$f->Entry(-textvariable => \$filename)->pack(-side => 'left',
-anchor => 'w', -fill => 'x', -expand => 1);
$f->Button(-text => "Exit", -command => sub { exit; } )->
pack(-side => 'right');
$t = $mw->Scrolled("Text")->pack(-side => 'bottom',
-fill => 'both', -expand => 1);
MainLoop;
Google found this:
http://www.tcl.tk/cgi-bin/tct/tip/26.xml
Finally, a virtual event has been added that is triggered whenever the selection in the widget changes. At first it may seem not so useful, but there are a number of situations where this functionality is needed. A couple of examples where I ran into the need for this may clarify this. On Windows, if the text widget does not have the focus, the selection tag is not visible. This is consistent with other Windows applications. However, when implementing a search mechanism, the found string needs to be tagged with the selection tag. (You want it to be selected). The search (and replace) dialog box has the focus however, so this selection tag is invisible. To make it visible, another tag was used to duplicate the selection tag. This is very easy when the functionality described here is available. Otherwise it is very difficult to do this consistently. Another occasion was when I was implementing a rectangular cut and paste for the text widget. This was based on adding spaces on the fly, while selecting the rectangle. If for some reason the selection changes (for instance on Unix another application gets the selection) these spaces need to be removed again. Doing this is virtually impossible without this functionality. With it, it becomes trivial. The functionality itself adds little or no overhead to the text widget.
I do not understand this...