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

Is there a global way, within a Perl/Tk script, to specify the size for ALL widgets? Like what you can do from the command line, but within the script?

I'd like particularly to include the menubar which I've gotten working by the slick, new-fashioned way according the the Mastering Perl/Tk book.

I'm hoping not to have to address each widget separately. And I particularly need to make the menubar more readable for some of my users.

Replies are listed 'Best First'.
Re: Tk font size for ALL widgets
by zentara (Cardinal) on Nov 14, 2007 at 17:56 UTC
    optionAdd works for most widgets, but the canvas needs special attention.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit(); $mw->optionAdd('*font', 'Helvetica 24'); my $menubar = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menubar); my $menu = $menubar->cascade(-label => '~File'); $menu->command(-label => '~New'); $menu->command(-label => '~Open'); $mw->Button(-text => 'test this font')->pack; $mw->Label(-text => 'test this font')->pack; my $text = $mw->Text( -height => 4, -width =>20)->pack; $text->insert('0.0','test this font'); my $canvas = $mw->Canvas->pack; my $font = $mw->Font(-family=> 'Helvetica', -size => 24); $canvas->createText( 0, 0, -anchor => 'nw', -text => 'test this font', -font => $font, ); MainLoop;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      That worked for everything I was using (no canvas) except the menubar. But even so it still helps a lot. So I do thank you kindly

      Any ideas on how to deal with font size in the menubar?

        This ought to give you the idea. You can also throw images in there, but there are limitations.
        #!/usr/bin/perl use strict; use warnings; use Tk; my $mw = MainWindow->new( -title => 'Testing Tk::Menu', -width => 500, -height => 100, -background => 'yellow', -name => 'Demo', ); $mw->minsize( 500, 300 ); my $bf = $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=>int(-18*18/14)); my $menubar = $mw->Menu( -type => 'menubar', -font => "Verdana 18 bold", # -font => 'big' ); $mw->configure( -menu => $menubar ); $menubar->configure( -font => "Verdana 18 bold" ); #$menubar->configure( -font => 'big' ); my $m1 = $menubar->cascade( -label => 'File', -tearoff => 0, -menuitems => [ [ Button => 'New', -font => "Verdana 18 bold", -command => \&create_new_file ], [ Button => 'Open', -command => \&open_file, -font => 'big', -background => 'black', -foreground=> 'white', ], [ 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. Cogito ergo sum a bum