Dear monks, this one is a bit unusual: my Tk app handles utf-8 strings entered into a Tk entry box fine, but when the same app is packaged into an exe with pp, some characters are corrupted. Specifically, ű becomes û and ő becomes õ (I hope these show up as intended here). They already show up incorrectly as you type them, and are printed to file incorrectly as well. This occurs both on Win7 and XP.
All other characters I tested are fine, including cyrillic and Arabic ones, but of course that's not entirely reassuring. How likely is it that other characters will also be corrupted? Is there any simple solution I could try? I can work around this with a simple
s/û/ű/g but that's no help if many other unknown characters are also corrupted. Is this problem in Tk? pp? Windows?
Interestingly, the two problem characters work fine when pasted into the entry box instead of typing them in.
Here's a short script that exhibits the issue (I imagine you'll have to switch to the Hungarian keyboard layout if you want to test it, given that the problem doesn't occur if you use Ctrl-c Ctrl-v):
use strict;
use warnings;
use Tk;
use utf8;
my $mw = Tk::MainWindow->new;
$mw->minsize(300, 250);
my $entered;
my $entry = $mw->Entry( -textvariable => \$entered, -width => 75, -tak
+efocus => 1 )->pack();
$entry->focus( -force );
open (OUT, ">>:encoding(UTF-8)", "_entered.txt");
my $go = sub {
print OUT "$entered\n";
};
my $buttgo = $mw -> Button( -text=>"Go",
-command => $go
) -> pack();
$mw->bind( '<Return>', $go );
my $buttexit = $mw -> Button( -text=>"Exit",
-command => sub {exit},
) -> pack();
Tk::MainLoop();
And here's the exe from the same script: https://www.dropbox.com/s/dyxir5rd4et0fj7/entry.exe
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.