As usual, the final solution was a bit more complicated than I thought, but I wanted to provide a final update in case others have the same issue.
The attached code shows what I did in order to translate unicode characters into ASCII with Text::Unidecode. This will translate the entire string on each keystroke, and works with cut-n-paste as well.
NOTE: when using a text variable for the text in the entry, you cannot simply re-assign text to it in the validatecommand() sub. One trick is to use afterIdle() to do that later.
Thanks again to all for the help!
Craig
#!/opt/homebrew/bin/perl use strict; use warnings; use Data::Dumper; use Tk; use utf8; use Text::Unidecode; my $mw = MainWindow->new(); my $textvar; my $e = $mw->Entry(-textvariable => \$textvar, -validate => 'key', -validatecommand => sub { my ($new,$changed,$old,$ix,$type) = @_; return 1 if (!defined($changed)); return 1 if ($new eq "") or ($type<0); $mw->afterIdle(sub{ $textvar = unidecode($new); print STDERR "ASCII: $textvar\n"; }); return 1; }, )->pack(); MainLoop;
In reply to My Solution: Tk Entry & Right Single Quote
by cmv
in thread Tk Entry & Right Single Quote
by cmv
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |