I've been struggling for a couple of years with the differences between the Linux and Windows versions of my TK based perl tools.
So one of my TK UIs in windows would fit nicely on a 1920x1080 screen,
but would expand strangely and overflow the display when opened in Linux.
It would take me several hours to re-layout the GUI to work with both applications
It turns out that the main problem was default font sizes.

The default Linux font was Helvetica 12 for most widgets, and the Windows font is Arial 8.
Once I figured that out, I looked around for some solutions to controlling the font sizes.
The Mastering TK books talk about using Xdefaults or TK::CmdLine,
but I am distributing my tools as wrapped executables and I cannot count on any kind of pre-existing environment

I finally found this link from the TCL wiki
https://wiki.tcl-lang.org/page/Changing+all+fonts+in+an+application

It was close to what I wanted (in TCL-TK ) But I wanted to have a little more control and set all the Label type widgets to use bold text
and all the entry type widgets with the same font but not bold

I came up with this solution that I wanted to share (and be able to search for later) I wrote a sub to defined the default fonts for my application
and then I call that sub immediately after creating my MainWindow

#main application our $MAIN_WINDOW=MainWindow->new; #make call here to init the fonts from the very beginning &init_mw_fonts($ctlRef,$MAIN_WINDOW); $MAIN_WINDOW->title("CadEnhance:Part Builder Schematic Symbol Creator" +); $MAIN_WINDOW->configure(-menu=>my $menubar=$MAIN_WINDOW->Menu); # # # MainLoop; sub init_mw_fonts{ #set the default font types or all of our widget classes my $ctlRef=shift; my $mw=shift; require allToolCtlVariables; my $boldFont =&my_tk_cfg_vars("BOLD_FONT") || &all_tk_cfg_vars("BOLD +_FONT"); my $normalFont =&my_tk_cfg_vars("NORMAL_FONT") || &all_tk_cfg_vars(" +NORMAL_FONT"); my $textFont =&my_tk_cfg_vars("TEXT_FONT") || &all_tk_cfg_vars("TEXT +_FONT"); #first set ALL fonts to $normalFont $mw->optionAdd("*font",$normalFont); #then we pick and choose the items we want to be bold foreach my $boldClass (qw(Checkbutton Label Listbox Button Menu Menubutton Message Radiobutton Scale + ProgressBar)) { $mw->optionAdd("*$boldClass.font",$boldFont); } #now set the text Font $mw->optionAdd("*Text.font",$textFont); } #This subroutine lets us program the fonts we want to use #and we can create a similar one for each application called #my_tk_cfg_vars which will override the global one sub all_tk_cfg_vars { my $selection=shift; my %gui_vars=( ENTRY_WIDTH=>80, CFG_ENTRY_WIDTH=>40, DT_ENTRY_WIDTH=>98, TEXT_WIDTH=>110, BACK_GROUND_COLOR=>"light grey", YPAD_SMALL=>0.5, YPAD_MED=>1.0, YPAD_LARGE=>5.0, XPAD_SMALL=>0.5, XPAD_MED=>1.25, XPAD_LARGE=>15, LABEL_FONT=>"Arial 9 bold", BOLD_FONT=>"Arial 9 bold", NORMAL_FONT=>"Arial 9", TEXT_FONT=>"Helvetica 10", ); if (defined ($gui_vars{$selection})) { return $gui_vars{$selection}; } else { return 0; } } sub my_tk_cfg_vars{ my $param=shift; return ""; #or override the values defined in all_tk_cfg_vars }

Hopefully this may help someone else who might be hitting the same issue


In reply to TK font control Linux Windows by boleary

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.