mpolo has asked for the wisdom of the Perl Monks concerning the following question:

I have a program written a few years ago to run a "quiz show" under Perl using the Tk library for windowing. This year I hit the problem that one of my "contestants" has an Š in his name, which does not exist in ISO-8859-1.

If I convert the script to Unicode using iconv, I can add the character to the name, but Tk seems to see every thing as ISO-8859-1, so that the Unicode characters all become 2 character blocks. I like the angstrom symbol and all, but not when I'm trying to get an Š. Looking through the search on the site and in the Internet, it seems that this is an admitted problem with Perl-Tk, which the author is working on.

But this leaves me with a bit of a quandary, as I need the program this evening (I suppose I should have had more foresight...). Is there any "easy" solution to this? For instance, is there an alternative toolkit to which I can convert the program without spending hours learning a new system? Or a way to force Tk to play nice with the Unicode? Or... If all else fails, I'll strip the accent from the name, but that wouldn't be my preferred solution.

I am using perl 5.8.8-5 (FC5) with perl-Tk 804.027-9.

Replies are listed 'Best First'.
Re: Using Unicode in Tk
by zentara (Cardinal) on Oct 21, 2006 at 13:10 UTC
    This is just a guess, which I got to work, on my machine anyways. I'm still in the woods with all these encoding problems. It's further compounded by the fact that my provincial editor, still shows the Š as an Angstrom. But this Tk script shows the letter properly for me in the label. I had to open it in yudit ( a unicode editor ) to copy-and-paste it in.
    #!/usr/bin/perl use warnings; use strict; use utf8; use Tk; #$Tk::encodeFallback=1; my $main = tkinit(); my $text = 'contestant has an Š' ; $main->Label(-text =>$text )->pack(); MainLoop;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      Thank you. I was missing the use utf8;. All is well with my program now.

      I suppose that means all the comments about Tk not working with Unicode that I found are outdated. Nice to know.

        You're right, Tk became Unicode-capable starting from 804.xxx versions, so now its just works.

        Few years ago there was a gap, however, when Unicode appeared in Perl and Tcl/Tk, but not in perl/Tk, now the situation improved,