use strict; use warnings; use Tk; my $tstate = 0; # State of the dynamic text my $mw = MainWindow->new( # Create a window -width => 300, -height => 110, ); $mw->minsize( 300, 110 ); $mw->fontCreate('standard_font', # ..and some fonts for it -family => 'Arial', -size => 12, -weight => 'normal'); $mw->fontCreate('alternate_font', -family => 'Times', -size => 24, -weight => 'bold'); $mw->fontCreate('my_default_font', -family => 'Sans', -size => 8, -weight => 'normal'); # $mw->configure(-font => 'my_default_font'); # '-font' is unknown to configure() # $mw->fontConfigure('my_default_font'); # Does nothing my $static_text_lbl = $mw->Label( # Uses the system 'default' font -text => 'UNCHANGING TEXT', )->pack(-anchor => "center", -side => 'top'); my $text_lbl = $mw->Label( # An object with an assigned font -text => 'DYNAMIC TEXT', -font => 'standard_font', )->pack(-anchor => "n", -side => 'top'); my $Exit_Btn = $mw->Button( # A button to exit -text => 'Exit', -width => 8, -command => sub { $mw->destroy }, )->pack(-anchor => 's', -side => 'bottom'); my $Toggle_Btn = $mw->Button( # ..and another to toggle the font -text => 'Toggle', -command => [ \&fix_fonts ], )->pack(-anchor => 's', -side => 'bottom'); MainLoop; # ---------- sub fix_fonts { if ($tstate ^= 1) { $text_lbl->configure(-font => 'alternate_font') } else { $text_lbl->configure(-font => 'standard_font') } } # [eof]