perl-tk icon indicating copy to clipboard operation
perl-tk copied to clipboard

Verbose font specification does not work

Open hakonhagland opened this issue 8 years ago • 1 comments

According Matering Perl/Tk, Chapter 3 one can use a verbose font specification when calling configure on a widget. However, the following does not work:

use feature qw(say);
use strict;
use warnings;
use Tk;
use Tk::BrowseEntry;

my $mw = MainWindow->new(-title => 'Font test');
my $f = $mw->Frame->pack(-side => 'top');

my $family = 'Courier';
my $size = 24;
my $bentry = $f->BrowseEntry(
    -label => 'Size:',
    -variable => \$size, 
    -browsecmd => \&resize_font
)->pack(-side => 'left');
$bentry->insert('end', (3 .. 32));

my $sample = $mw->Entry(-textvariable => "Sample text")->pack(-fill => 'x');

resize_font();

MainLoop;

sub resize_font {
    say "Setting new size: $size";    
    #$sample->configure( -font =>   "$family $size" );    # <--- CASE 1
    #$sample->configure( -font =>  [ $family, $size ] );  # <--- CASE 2
    $sample->configure(
        -font =>  [ -family => $family, -size => $size ]  # <--- CASE 3
    );
}

when running this script, the font of the $sample Entry is never resized. However, the less verbose forms in CASE 1 and CASE 2 works fine. I could not find this behavior documented in Tk::Font either.

hakonhagland avatar Mar 29 '17 20:03 hakonhagland

I think the book was written around 2002, and at this time Tk was at version 800. Maybe these feature got lost during the transition to Tk 804. Probably it could be checked by building Tk 800...

eserte avatar Nov 11 '17 21:11 eserte