eserte / perl-tk

the perl module Tk
https://metacpan.org/release/Tk
Other
44 stars 31 forks source link

Verbose font specification does not work #27

Open hakonhagland opened 7 years ago

hakonhagland commented 7 years ago

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.

eserte commented 6 years ago

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...