in reply to umlauts in Tk widgets

You have an encoding problem. Try this:
use Encode; use Tk; my $bytes = "öäü"; my $text = decode("utf-8", $bytes); my $mw = MainWindow->new; $mw->Label(-text => encode("iso-8859-1", $text))->pack; MainLoop;
The default font seems to be using a latin-1 mapping.

How "öäü" is represented will depend on your text editing environment. Mine happens to be UTF-8. Alternatively I could have used use utf8; instead of decode().

Update: The encoding to iso-8859-1 is not necessary. Tk seems to be one of the very few external modules which is text-aware (yeah!). Both of these invocations will produce the same result:

$mw->Label(-text => encode("iso-8859-1", $text))->pack; $mw->Label(-text => $text)->pack;

Replies are listed 'Best First'.
Re: umlauts in Tk widgets
by Kardan (Initiate) on Jul 16, 2008 at 17:38 UTC
    Great thanks for your replies!

    As i read the given article in german already, i didn't find anything new in the english version.

    I played around with your snippets and updated my script:
    #! /usr/bin/perl -w use strict; use Tk; # use utf8; # <- makes everything even worse use Encode; my $enc = 'utf-8'; my $umlauts = 'öäü'; my $text = decode("utf-8", $umlauts); my $mw = MainWindow->new; # scrambled string widgets $mw->Label(-text => encode($enc, $umlauts))->pack; $mw->Label(-text => decode($enc, $umlauts))->pack; $mw->Label(-text => $umlauts)->pack; $mw->Label(-text => $text)->pack; $mw->Label(-text => encode("iso-8859-1", $umlauts))->pack; # the only one that creates shiny umlauts $mw->Label(-text => encode("iso-8859-1", $text))->pack; MainLoop;
    So now I am able to convert strings loaded from files. Great thanks so far!

    But what about those umlauts typed into Entry or Text and compareable widgets?

    > How "öäü" is represented will depend on your text editing environment.
    How can I get information about this?