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

I use $label=$main->Label(-textvariable=>\$txt, -font => 'arial 190'); in a perl Tk script that should produce a label that has a font as big as the screen. But I can use 'fixed 90' or 'fixed 190', it never gets higher than about 1cm. What am I doing wrong?

Replies are listed 'Best First'.
Re: Huge font in perl Tk
by thundergnat (Deacon) on Oct 19, 2005 at 01:05 UTC

    Fixed is a bitmapped font and only supports a few predetermined sizes. It will select the size that is closest to the requested size. The largest size supported seems to be about 70. On my (WinXP) system, once you get above 121, it turns to Helvetica.

    Here's a little utility I wrote to mess around with fonts and sizes. Use the up and down arrows to change the size quickly.

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $fontname = 'Times'; my $fontsize = 200; my $top = MainWindow->new; my $cframe = $top->Frame->pack(-anchor => 'w'); my $label = $top->Label( -text => 'This is a label', -font => "{$fontname} $fontsize", )->pack; my $sizelabel = $cframe->Label( -text => $fontsize )->grid(-row => 1, -column => 3, -padx => 2); my $fontlist = $cframe->BrowseEntry( -label => 'Font', -browsecmd => sub{ fontconfig($label, $fontname, $fontsize) }, -variable => \$fontname, )->grid(-row => 1, -column => 1, -padx => 8); $fontlist->insert ('end', sort $top->fontFamilies); my $smaller = $cframe->Button( -text => 'Smaller', -command => sub{ $fontsize--; fontconfig($label, $fontname, $fontsize); $sizelabel->configure(-text => $fontsize); }, )->grid(-row => 1, -column => 2, -padx => 2); my $bigger = $cframe->Button( -text => 'Bigger', -command => sub{ $fontsize++; fontconfig($label, $fontname, $fontsize); $sizelabel->configure(-text => $fontsize); }, )->grid(-row => 1, -column => 4, -padx => 2); $top->bind('<Up>' => sub{$bigger->invoke}); $top->bind('<Down>' => sub{$smaller->invoke}); $top->focus; MainLoop; sub fontconfig{ my ($widget, $fontname, $fontsize) = @_; $widget->configure(-font => "{$fontname} $fontsize"); } __END__
      Thanks a lot for this program! It showed me that there are actually 3 fonts on my system that can be scaled to any size: bitstream, luxi and utopia. That's great, so my countdown works now! I could not have found the working fonts without your program!
      I also installed freefonts, but didn't get any more hugely scalable fonts in the font-selector by thundergnat even after restarting X. But those three are enough for me anyway...
      Your test program was very helpful. I am porting a Perl Tk program from MAC to Windows and the fonts were causing me problems.
Re: Huge font in perl Tk
by GrandFather (Saint) on Oct 18, 2005 at 22:51 UTC

    The following works fine for me under Windows XP:

    use strict; use warnings; use Tk; my $main = MainWindow->new (); my $label = $main->Label(-text => 'Text', -font => 'arial 490')->pack +(); MainLoop;

    Note that Label doesn't seem to understand -textvariable


    Perl is Huffman encoded by design.
      Doesn't work here (gentoo linux). Someone on IRC tested my code and it produced a huge font, but I just get the 1cm font on my system. What could be wrong?

        Appart from the textvariable/text thing, the code seems sensible. The only things I can think of are fairly bizzare - like case sensitive name (but then it shouldn't work at all), or the font system doesn't allow you to generate a larger size than that with that face (you could try a different face).


        Perl is Huffman encoded by design.

        Works here (gentoo linux). To be honest, I suspect that you need to emerge some font stuffs or something. e.g., freefonts (boy did that help - I wish I knew about that set years ago before I got gentoo...). Or perhaps your X server or X font server ... it's hard to tell. Can you bring up other applications and get huge fonts, say in openoffice.org or something?