[Tkinter-discuss] Text widget, fonts, on OS X: questions and thoughts

Jeff Epler jepler at unpythonic.net
Tue Mar 30 08:02:12 EST 2004


As noted in another post, you should probably be able to use
    t.tag_configure("mytag", font=font_specifier)
where t is your text widget and font_specifier names your font.

It may be the syntax you're using to describe the font that is wrong.
"-family system -size 10" looks like the value for a "font configure" or
"font create" command.  Please read the manpage for font(n) down at FONT
DESCRIPTION.  Syntax 3 is probably the one you want:
       [3] family ?size? ?style? ?style ...?
              A  properly  formed list whose first element is the desired font
              family and whose optional second element is  the  desired  size.
              The  interpretation of the size attribute follows the same rules
              described for -size  in  FONT  OPTIONS  below.   Any  additional
              optional arguments following the size are font styles.  Possible
              values for the style arguments are as follows:

                     normal      bold        roman      italic
                     underline   overstrike
In this case, you should try
    t.tag_configure("mytag", font=("system", 12))
I just tried the following in an interactive session, and it seemed to work:
    >>> import Tkinter
    >>> t = Tkinter.Text()
    >>> t.pack()
    >>> t.insert("end", "xyzzy", "mytag")
    >>> t.tag_configure("mytag", font=("courier", 36))

If combining a font size with the font name "system" doesn't work,
maybe it's because "system" is one of the special macintosh fonts listed
at the end under PLATFORM-SPECIFIC ISSUES, so font=("system", 12) is not
an example of font naming style 3, but style 2 (system font) with extra
junk at the end.  I'm not sure what to do in this case, but it probably
involves using the tkFont module to find the details of the "system"
font, then creating a new font with the same details.
    >>> t.tk.split(t.tk.call("font", "actual", "fixed"))
    ('-family', 'fixed', '-size', '12', '-weight', 'normal', '-slant',
    'roman', '-underline', '0', '-overstrike', '0')

Jeff



More information about the Tkinter-discuss mailing list