FE 'tkGooie' Utilities

'SELECTORtools' group

used in the several
FE subsystems

(FE = Freedom Environment)

The font names list on the left
shows the fonts that were
'discovered' on the computer.

FE Home Page > FE Downloads Page >

FE 'tkGooies' Description Page >

FE 'tkGooies' 'SELECTORtools' Page >

This FE Font Selector GUI Page

Font Selector GUI
(used in software at freedomenv.com)

In 2012 August, I published the Tk script code for a simple RGB color selector GUI on the wiki.tcl.tk web site, in a page titled 'A non-obfuscated color selector GUI'.

I had one more 'selector' script that I thought would be helpful to publish on that site --- helpful to Tcl-Tk 'newbies' who need complete examples of working, useful scripts to speed up their learning process --- and perhaps helpful to someone still looking for a better font selector GUI.

By doing a search on the 'wiki.tcl.tk' site with keywords like 'font chooser', you will find that everyone seems to have their own idea as to what they need in a font chooser.

Some titles on that site:
'A little font chooser', 'A small font chooser', and 'Another Font Chooser Dialog'.

And there is the code for yet another font chooser in the book 'Practical Programming in Tcl and Tk' (4th edition) by Brent Welch, Ken Jones, and Jeffrey Hobbs --- page 643 --- where this image is shown --- along with the code used to generate it.

I built my font selector based on that code --- but I reorganized the code according to a 'canonical' code structure that I have used for all my Tk scripts written in the past 10 years or so (on the order of a hundred Tk scripts):

  0) Set general window parms (win-name, win-position, win-color-scheme,
                               fonts, widget-geom-parms, win-size-control).

  1) Define ALL frames (and sub-frames).  Pack them.

  2) Define & pack all widgets in the frames.

  3) Define key/mouse action BINDINGS, if needed.

  4) Define PROCS, if needed.

  5) Additional GUI initialization (typically with one or more
                                    of the procs), if needed.

When I need to find a proc (or a binding, or a widget definition, or an example pack statement, etc. etc.) in my scripts, I can find what I need relatively quickly.

In addition to the code reorganization, I added a few features to the example presented in the Welch book. Some of those features can be seen by comparing the following image to the image above.

The code for this font selector GUI is about twice as long (in bytes/characters) as the code for the color selector GUI.

Part of the reason it is so long is that I have 'left in' many of my comments that explain the usage of the GUI and the structure and intent of the code. The comments may be helpful to Tcl-Tk 'newbies' -- to help them read the code.

The code can be helpful, to give some examples of using widgets not used in the color selector GUI script --- to aid Tcl-Tk 'newbies' who are looking for code samples.

(Even though it might take more than 30 PageDown key strokes to page through this code image, when considered in bytes, the file holding this code is less than 2% of the size of the typical JPEG file from a 12 megapixel digital camera.)

The widgets

The widgets in this font selector GUI include a 'listbox' (with y-scrollbar), a 'text' widget with both x and y scrollbars, 'radiobutton' widgets, 'checkbutton' widgets --- even a 'tk_optionMenu' button widget (a predecessor of the newer 'spinbox' widget).

Alternatively, I could replace the 'tk_optionMenu' button with the 'spinner' proc at the 'spinbox' page at 'wiki.tcl.tk'. It is "a concoction of a 1-line high listbox with two tiny buttons", so it would run with old 7.x wish interpreters. Maybe I will do that --- someday.

    The 'tk_optionMenu' widget can be seen in the screenshot at the top of this page, but in the image just above, you can see that the 'tk_optionMenu' widget was replaced by a 'scale' widget --- as explained in the '2012oct30 UPDATE' below.

Raison de etre (of yet-another font selector)

After I retired and started assembling the software in my 'Freedom Environment' (FE) software system (see www.freedomenv.com), I used this font selector GUI as a font setting utility in the 'xpg', 'feAppMenus, and 'feHandyTools' subsystems of my Freedom Environment software.

That was my single, main motivation for making this font selector. It is a font selector that blends in with the other Tk GUI's in my FE systems. Plus, it does exactly what I need it to do.

I provide all the FE code as free and open source code. Besides an FE RGB-color-selector and this font-selector, I have provided the code for the FE 'xpg' utility at the 'wiki.tcl.tk' site.

The conversion to a stand-alone script

In my FE subsystems, I use some Tk 'include' files in my scripts to provide some parameter setting that is shared with other utility scripts. I have replaced the corresponding 'source' statements with the essential Tk statements from those 'include' code-files.

(Some of the 'include' statements, involving parameters for 'entry' and 'message' widgets, widgets not used in this GUI, may be left in this code --- and commented, for the most part. Those statments can be useful if other GUIs are made using this code as a starting point.)

Window expansion and contraction

For this particular GUI, when one chooses to display a font in a really big size, the sample text widget needs to be allowed to expand --- to full screen size if necessary.

To help restore the window to a more desirable size, when going back to a smaller font size from a really big font size, there is a 'DwnWin' button on the GUI.

You can click on that button repeatedly to quickly down-size the window, in increments of about 10%. I find this much more speedy and less frustrating than trying to grab a really thin edge of the window, to drag the window edge, to make a smaller window.

Improving widget behavior

As I do in all my Tk scripts, I have put the four main pack parameters --- '-side', '-anchor', '-fill', '-expand' --- on the 'pack' command for the various frames and widgets. That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window.

I think I have found a pretty-good setting of the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various widgets. In particular ...

The 'listbox' widget and the sample 'text' area widget expand/contract appropriately when the window size is changed --- and button and label widgets stay fixed in size and relative-location as the window size is changed.

However, if anyone wants to change the way the GUI configures itself as the main window size is changed, they can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various widgets --- to get the widget behavior that they want.

I am not totally satisfied with the behavior of the listbox and text-box during window expansion and contraction. It is rather challenging to get nice behavior of two side-by-side widgets that expand when the window expands.

One approach might be to add an x-scrollbar to the listbox and only let it expand in the y-direction. (NOTE: I did this in a later update.) This would give more room for the text-box when the window expands. In any case, you have the code, so you can experiment with these factors to get widget behavior that is more pleasing to you during expansion and contraction of the window.


Here is a link to the CODE for Tk script
select_tkFont_standAlone.tk. Use a different name, if you prefer.

I hope that some Tcl-Tk 'newbies' can learn from this useful script and its many widget types.

Thanks to Brent Welch et. al. for putting in the tremendous amount of work it takes to provide 'lasting' reference works on the Tcl-Tk programming system --- where twenty to thirty years is 'lasting' in this fast moving information age.

And thanks to Ousterhout for

  • the vision to create the Tk toolkit,

  • the excellent initial implementation of that vision that makes Tk such a joy to use compared to coding GUI's in a language such as C or C++, along with the many library routines involved

      (He has sheltered us --- leaving us only the essentials to specify --- hiding a lot of coding, underneath the covers, that we should not really have to do. Yet he allowed for a tremendous amount of flexibility and capability. He made a tremendous number of excellent choices.)

  • the perspiration that it took to implement those hundreds (nay thousands) of GUI parameters and functions that give Tcl-Tk code nerds (I mean warriors) such an array of coding weapons.

2012oct28 UPDATE

The code that was above has been replaced. The new code includes the following changes:

  • Comments were re-organized and improved --- and it was noted in the comments that this is a 'stand-alone' script that was converted from a script that used 'source' statements to incorporate 'common' code from some Tk 'include' files.

  • Indenting was improved to a more consistent format, and some white-space at the start of many widget-definition and widget-packing lines was removed.

  • Braces were added to 'expr' statments.

  • The bindings section was compacted.

  • The font setting section was compacted somewhat.

  • The initial part of the code was re-organized to follow the 'canonical' format that I use in most of the other Tk scripts that I have posted on 'wiki.tcl.tk'. That format is described on the page titled 'A Canonical Structure for Tk Code --- and variations'.

  • Removed a superfluous 'pack' statement that was keeping the text area from expanding nicely for large fonts. The text area behavior, under certain window expansion conditions, is still not quite what I would like. I may need to add some configure height and width statements to the 'font_update' proc.

2012oct30 UPDATE

This font-selector utility was used in the Tk script whose code is on the 'wiki.tcl.tk' page titled "A GUI for making 'Title Blocks' ... with text, fonts, colors, images".

So you can check the 'set_font' proc in that code for an example of how to make a call to this font-selector script and how to use the output.

In the process of using the font-selector for that utility, I made some more changes to the font-selector code. The main changes are:

  • Replaced the 'tk_optionMenu' widget with a 'scale' widget.
  • Improved the setting of window 'minsize'.
  • Moved 'app-vars' initial settings to the bottom of the script.

The 'scale' works quickly and allows for specifying a 'fine-grain' of font sizes. Nowadays, with scalable fonts being the norm, it is desirable to be able to pick any integer from about 6 to 100 --- pixels or points --- for a font-size. If you want to go higher than 100, simply go to the code that defines the 'scale' and change 100 to 300 or whatever.

Having the 'app-vars' initialization collected in one place makes it easier to avoid coding errors. For example, the setting of all 6 font attributes for an initial, default font are now all in one place. This makes it a lot easier to tell if something is missing or duplicated or over-ridden or whatever.

So, again, I have replaced the code above with the new code.

2012nov03 UPDATE

Just above the code listing above, I mentioned how I might make some changes to the GUI to get better behavior during window expansion and contraction. Well, I was using the font selector with the 'TitleBlock' maker that I posted at the 'wiki.tcl.tk' page titled "A GUI for making 'Title Blocks' ... with text, fonts, colors, images".

In the course of using the font selector with that utility, I found that the GUI definitely needed some attention. I have made the following changes:

  • Added an x-scrollbar to the listbox.

  • Changed the 'pack' of the listbox to allow y-expansion, not 'both'.

  • Changed '-expand' from 1 to 0 in the 'pack' of scale.

  • Added '-repeatdelay' to scale.

  • Changed several other pack parms to get better widget behavior if the window expands.

  • Changed calculation of win-min-width (it was too large).

  • Changed initial win-position.

  • Changed scale max from 100 to 300.

So, again, I replaced the code above with the new code. Hopefully, any further changes to improve GUI behavior during window expansion and contraction will be tiny compared to these changes.

2012nov18 UPDATE

I have made two relatively minor changes:

  • I added an 'UpWin' button.

  • I put the text of labels, buttons, radiobuttons, and checkbuttons into a text array in one section of the code, so that Tcler's can easily 'internationalize' the text in this GUI.

In relation to the first change:

Having the 'UpWin' button is handy after the display of a very large-sized font has caused the window to expand to full size, and then the user down-sizes the window after a smaller font is shown.

Tk seems to 'forget how to up-size' the window after it is downsized from full-screen size --- for example, if the user does the downsizing, by 'grabbing' the window edge or by using the 'DwnSize' button. (The 'DwnSize' button is helpful, because Tk does not handle the window downsizing when the font is downsized.) If the user starts choosing very large font sizes again, Tk no longer enlarges the window automatically. Furthermore, if the user down-sized a little too far with the 'DwnSize' button, the user will need to up-size.

Rather than trying to 'grab' the very narrow edges of the window to enlarge or downsize the window, it is more convenient to have 'UpSize' and 'DwnSize' buttons.

In relation to the 2nd change:

I have started the practice of using a text-array for text in labels-etc, located in 'section-zero' of the code, for ease of internationalization, as described on the page A Canonical Structure for Tk Code --- and variations.


By the way, the 'ColorMe' button on the GUI uses an external color selector script to set a new 'palette' for the font selector GUI. You can get the color selector script from the page titled 'A non-obfuscated color selector GUI' that I mentioned in the first line at the top of this page.

The 'ColorMe' button is just there 'for grins'. For example, if someone gives you flack about how all Tk GUI's look so plain, at least you can show them that you can quickly change to a blue, orange, chartreuse, or pink GUI.

Bottom of this page for
the Freedom Environment FONT SELECTOR GUI
--- a utility in the FE 'tkGooies' system,
in the 'SELECTORtools' group.

To return to a previously visited web page location, click on the Back button of your web browser a sufficient number of times. OR, use the History-list option of your web browser.
OR ...

< Go to Top of Page, above. >

Page history:

This code was posted on 2012 Aug 13 at http://wiki.tcl.tk/36788.

This FE web page was created 2014 May 05 --- as a backup and alternative to the wiki.tc.tk page.

This page was changed 2015 Oct 05.
(Small format changes.)

Page was changed 2019 Feb 23.
(Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)

Page was changed 2019 Jun 13.
(Specified image widths in percents to size the images according to width of the browser window.)

The code here MAY become more 'up-to-date' than the code posted on the Tcler's Wiki --- wiki.tcl-lang.org --- formerly wiki.tcl.tk.