Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to print a Euro symbol () in a PerlTk Label widget.

by Ba1rdsy (Initiate)
on Sep 04, 2012 at 12:57 UTC ( #991618=perlquestion: print w/ replies, xml ) Need Help??
Ba1rdsy has asked for the wisdom of the Perl Monks concerning the following question:

I have a PerlTk app which displays billing information for mobile phone subscribers. Its a win32/64 app so I am using activestate 5.10.0. The particular chunk of code I working with looks like this:
$bill_f->Label( -text => sprintf("\$%.2f",$bill->{RENTAL}))->grid(); $bill_f->Label( -text => sprintf("\$%.2f",$bill->{USAGE}))->grid(); $bill_f->Label( -text => sprintf("\$%.2f",$bill->{OTHER}))->grid(); $bill_f->Label( -text => sprintf("\$%.2f",$bill->{TOTAL}))->grid();
I need to update the app for European users and one thing they keep asking for is to replace those pesky dollar signs with euro symbols. Ive tried using \ in the sprintf but that doesnt work, nor have the fancier ways of using UTF-8 codes that Ive tried. Any suggestions?

Comment on How to print a Euro symbol () in a PerlTk Label widget.
Download Code
Re: How to print a Euro symbol () in a PerlTk Label widget.
by Anonymous Monk on Sep 04, 2012 at 13:01 UTC

    Ive tried using \ in the sprintf but that doesnt work, nor have the fancier ways of using UTF-8 codes that Ive tried. Any suggestions?

    Prove it?

     perl -MTk -e " tkinit->Label( -text => qq{\x{20AC}} )->pack; MainLoop; "

Re: How to print a Euro symbol () in a PerlTk Label widget.
by choroba (Abbot) on Sep 04, 2012 at 13:09 UTC
    Ive tried using \ in the sprintf but that doesnt work
    You probably forgot to use utf8.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: How to print a Euro symbol () in a PerlTk Label widget.
by Ovid (Cardinal) on Sep 04, 2012 at 15:51 UTC

    If the answers above confuse you, what's going on is that the first one has this:

    perl -MTk -e "tkinit->Label( -text => qq{\x{20AC}} )->pack; MainLoop;"

    For that, we use \x{20AC}, the UTF-8 code for the Euro symbol and, sure enough, on my box, it displays a Label with the Euro symbol.

    In the second example, the author suggests using the utf8 pragma. That's because this:

    perl -MTk -e "tkinit->Label( -text => qq{} )->pack; MainLoop;"

    ... will probably show a Label with a bunch of funny characters because Perl doesn't realize that the symbol is a UTF-8 character, but interprets it as a byte string. The utf8 pragma tells perl (the interpreter) that your Perl (source code) is written in UTF-8 and it should show up correctly with this:

    perl -MTk -e "use utf8; tkinit->Label( -text => qq{} )->pack; MainLoop;"

    However, you've mentioned that you've tried both methods and they've failed to work. This implies that something else is diddling your input and output. Have you tried looking for anything else that is messing with your encodings? You could also check to see if your PERL_UNICODE environment variable has been set to something you don't expact.

    You could also try utf8::all, a pragma that tries to convert all input and output to UTF-8, including noting that your source code is also UTF-8 (though this is a blunt instrument which might have side-effects if you're messing with your encodings). If you do this and you use autodie, make sure that you use at least version 2.12 of the latter as earlier versions break utf8::all.

Re: How to print a Euro symbol () in a PerlTk Label widget.
by zentara (Archbishop) on Sep 04, 2012 at 16:42 UTC
    Here is another example:
    #! /usr/bin/perl use Tk; use charnames ':full'; my $top = new MainWindow; $top->Label(-bg=> 'white', -font =>['Arial',18,], -text =>"Euro sign: \x80") +->pack; $top->Label(-bg=> 'white', -text => "This is the euro sign: \N{EURO SIGN}")-> +pack; $top->Label(-bg=> 'white', -font => "-misc-fixed-bold-r-normal--13-120-75-75-c-70-iso8859-15 +", -text => "Euro sign: \x80")->pack; MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thanks very much, the
      $top->Label(-bg=> 'white', -text => "This is the euro sign: \N{EURO SIGN}")-> +pack;
      version did exactly what I was looking for!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://991618]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-07-29 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (226 votes), past polls