in reply to how to change the font of a perl tk gui

This short programme demonstrates how to change font size. I hope it can help you.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Font; sub change { my ($size_ref, $change, $l) = @_; $$size_ref += $change; $l->configure(-font => $l->fontCreate(-size => $$size_ref)); } my $mw = 'MainWindow'->new(-title => 'Scalable'); my $size = 12; my $font = $mw->fontCreate(-size => $size); my $l = $mw->Label(-text => 'Some text', -font => $font)->pack; my $f = $mw->Frame->pack; my $plus = $f->Button(-text => '+', -command => [\&change, \$size, 1 +, $l])->pack(-side => 'left'); my $minus = $f->Button(-text => '-', -command => [\&change, \$size, -1 +, $l])->pack(-side => 'right'); my $quit = $mw->Button(-text => 'Quit', -command => sub { exit })->pack; MainLoop();
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: how to change the font of a perl tk gui
by ghosh123 (Monk) on Aug 16, 2013 at 14:07 UTC

    Hi,
    It is easy for a Tk::Label widget to change its font by passing the $l object to the change(). But in my case , how can this be achieved , where I have Frames and on that HList widget and ItemStyles .

        Hi
        The RefontTree is working fine. I have included the following piece of code ,to the above long code I have given before, in between the 'Select File' Label and BrowseEntry packing. The fonts are reducing when I select a small font but the overall Tk Mainwindow size is not reducing with reduction of the font.
        This is as opposed to the RefontTree link above given by you. In that link, the gui size is also increasing and reducing according to the font chosen.
        Following is the code

        my $menubutton = $userframe->Menubutton(-text=>"font" , )->pack(-side= +>'left'); #$menubutton->cascade(-label => "preference",-command => sub{ pref{}}) +; $menubutton->command(-label => "change", -command => sub {print "comma +nd font \n"; my $font = $mw->FontDialog->Show; if (defined $font) { $mw->RefontTree(-font => $font); } });