How does one change the font in the wish widgets

Purpose: to describe the alternatives one has in specifying fonts in wish widgets.

In June, 1999, Markus Pietrek wrote on news:comp.lang.tcl :

"... changing the font of the window widget (which is done with <widgetpath> configure -font "Helvetica 10") is not enough, because you have to do it for each (child) widget.

So use the option database. In the wish program, write at the very beginning

 option add *font "Helvetica 10"

(or whatever font you want).

escargo 2012-09-25 - How does that work for fonts whose names include a space?

RLE (2012-09-27): The best way to avoid the space issue is to use a named font:

 font create mynewfont -family "font name with space" -size 12 
 option add *font mynewfont

This also gives you the option to later do:

 font configure mynewfont -family "another face" -size 24 -slant italic

And have every use of that "named font" switch faces, sizes, and become italic.

An alternative to users hard coding fonts in scripts is to write the tk code to read resources in from files. For instance, one can use the Tk option command to read a resource file. See for pointers to Tk code to assist in writing applications which appear to use resources like other X applications.

LV As far as I know, no one has yet written a Tk package that works in a cross platform manner for this type of thing. However, it would be a wonderful thing to have.

Be sure to see Practical Guide to Choosing Fonts here on Wiki as well.

If you're going to use the option database, my option tutorial [L1 ] is very useful reading. DKF (404 File Not Found as of 2012-09-25 - escargo)

Eric Brunel offered this sage counsel in the midst of a c.l.t thread: "... -font {-size 10.0}

Try: ... -font {-size -10}

We've had the same kind of problems on a cross-platform application and it was the solution. In theory, a positive font size should be what you want: it is supposed to be adjusted according to the screen resolution to look the same on each platform. In practice, the result is a huge font on Windows, a normal font on Solaris and a super-tiny font on Linux. Specifying a negative font size set it in screen points, whatever the screen resolution is. It should be worse, but it actually felt better for us: the font looked the same on all platforms."

IDG suggested: "Alternatively, use winfo screenwidth to find out what size screen you're running on, then set tk scaling to something sensible, and continue to use font sizes without the -. (Set tk scaling before drawing any widgets)."

SRT observed, "... or fix the dpi setting of the X11 server, e.g. by using

    startx ${HOME}/.xsession -- -dpi 100


    startx ${HOME}/.xsession -- -dpi 75

to start X."

See also: tk scaling, font