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

Hi all, My setup is Activeperl v5.8.4 build 810, Tk v804.026 running on Win2K.
I wrote a little test program that uses Tk to display a window with a menubar along the top.
I have tried to adjust fonts globally for the Menu but where
I have tried to change the code, it has not worked -
see lines marked: # HAS NO EFFECT!
I can change the font for individual Menu items, but I would
like to change the font for the entire menu including the label 'File'.
Can anybody point me in the right direction?
# Menu.pl use strict; use warnings; use diagnostics; use Tk; my $mw = MainWindow-> new(-title => 'Testing Tk::Menu', -width => 500, -height => 300, -background => 'yellow', -name => 'Demo', ); $mw-> minsize(500,300); my $menubar = $mw-> Menu(-type => 'menubar', -font => "Verdana 14 bold", # HAS NO EFFECT! ); $mw-> configure(-menu => $menubar); $menubar-> configure(-font => "Verdana 14 bold"); # HAS NO EFFECT! my $m1 = $menubar-> cascade ( -label => 'File', -tearoff => 0, -menuitems => [[Button => 'New', -font => "Verdana 16 bold", # OK -command => \&create_new_file ], [Button => 'Open', -command => _file ], [Button => 'Exit', -command => sub ], ] ); MainLoop; sub create_new_file { print "create_new_file...\n"; } sub open_file { print "open_file...\n"; } __END__
My first question on Perl Monks - hope I got it right!

Replies are listed 'Best First'.
Re: Setting fonts in Tk Menu's
by zentara (Cardinal) on Nov 12, 2004 at 15:42 UTC
    I realize it's your first post, but you didn't cut&paste complete code. Always check your code after pasting. Your button commands for Open and Exit are missing.

    But back to your problem. It works for me on Linux. Maybe on Windows, you need to create your font first, like this: (Notice you can refer to the font by object or 'tag-name'

    !/usr/bin/perl use strict; use warnings; use diagnostics; use Tk; my $mw = MainWindow->new( -title => 'Testing Tk::Menu', -width => 500, -height => 300, -background => 'yellow', -name => 'Demo', ); $mw->minsize( 500, 300 ); my $bf = $mw->fontCreate('big', -family=>'courier', -weight=>'bold', -size=>int(-18*18/14)); my $menubar = $mw->Menu( -type => 'menubar', -font => $bf ); $mw->configure( -menu => $menubar ); #$menubar->configure( -font => "Verdana 14 bold" ); my $m1 = $menubar->cascade( -label => 'File', -tearoff => 0, -menuitems => [ [ Button => 'New', #-font => "Verdana 16 bold", # OK -font => 'big', -command => \&create_new_file ], [ Button => 'Open', -command => \&open_file ], [ Button => 'Exit', -command => sub {exit} ], ] ); MainLoop; sub create_new_file { print "create_new_file...\n"; } sub open_file { print "open_file...\n"; } __END__

    I'm not really a human, but I play one on earth. flash japh
Re: Setting fonts in Tk Menu's
by zentara (Cardinal) on Nov 12, 2004 at 15:53 UTC
    I forgot to mention the nice Tk module called Tk::FontDialog. It allows you to recursively go thru widgets and change fonts. It is used something like this:
    use Tk::FontDialog; my $fd = $mw->FontDialog( -nicefont => 0, -title => 'Select Font', -applycmd => \&apply_font, -fixedfontsbutton => 1, -nicefontsbutton => 1, ); sub apply_font { my $font = shift; if ( defined $font ) { $rotext->configure( -font => $font ); $mw->RefontTree( -font => $font ); $top->RefontTree( -font => $font ); } }

    I'm not really a human, but I play one on earth. flash japh