The selection in the text widget is handled by setting the tag sel
for the selected range of characters. This tag can be removed like this:
.t tag remove sel 1.0 end
assuming the pathname of your text widget is .t
. This specifies that for all characters from the first (1.0
) to the character position after the last character (end
) the tag sel
is to be removed.
Note: normally when removing a tag one has to deal with the possibility that it has been assigned to multiple ranges in the text. The tag removal invocation above clears the tag from the whole text, and that's fine for the selection tag since you're (usually) only supposed to have one selected range anyway. If there are multiple ranges that have the tag foo
and you want to clear just one of them, you first need to find the starting and ending indices of that range and clear (by calling tag remove
) the tag only between those.
Note 2: All this is assuming that the visible effect is actually caused by the sel
tag getting set. In Tk, it's not a standard binding for button 2 to set this tag: it could be that some non-standard binding in Perl-Tk sets some other tag that is displayed visually in the same way as the sel
tag is. For further investigation, this command may be useful:
.t tag names $placeWhereIRightClicked
(again assuming the pathname of your text widget is .t
, and that placeWhereIRightClicked
holds the index of the place where the right clicking occurred) will tell you all tags that are active at that index.
(The command
.t tag names
will list tags for the whole text.)
TkDocs has an article about the text widget where the tag remove
command is mentioned, but how to do it in Perl-Tk isn't showed.
The CPAN documentation for the text widget says that the syntax for the command is
$text->tagRemove(tagName, index1, ?index2, index1, index2, ...?)
so I suppose
$text->tagRemove('sel', '1.0', 'end')
or something like that is the way to do it (no Perl, can't test).
(Note: the 'Hoodiecrow' mentioned in the comments is me, I used that nick earlier.)