[Tkinter-discuss] System Font Size

Fuzzyman fuzzyman at voidspace.org.uk
Tue Jul 11 17:03:52 CEST 2006


Jeff Epler wrote:

>If you want to find the default font used for a particular item, create
>one and interrogate it:
>    >>> b = Tkinter.Button(app)
>    >>> b.cget("font")
>    '-monotype-arial-medium-r-normal-*-12-*-*-*-p-*-iso8859-15'
>  
>
Wow, on windows I get :

    '{MS Sans Serif} 8'

That's pretty different. :-)

If I then change my system font size to "extra large" and repeat the
exercise, the default font size is unchanged. The text on the title bar
is made bigger, but buttons created have the same smaller size text.

Looks like I'll have to find a win32 way to check the system settings. :-(

Thanks anyway Jeff.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

>(in this case, it's a Linux system with the fonts coming from the X
>resource database in XLFD format)
>

>You can find out details of the font using the tkFont module:
>    >>> import tkFont
>    >>> f = tkFont.Font(b, b.cget("font"))
>    >>> fo.metrics()
>    {'fixed': 0, 'ascent': 11, 'descent': 3, 'linespace': 14}
>    >>> fo.configure()
>    {'family': 'arial', 'weight': 'normal', 'overstrike': '0', 'size': '9',
>    'slant': 'roman', 'underline': '0'}
>    >>> fo.measure("Hello World")
>    64
>
>You can construct a new font similar to an existing one:
>    >>> fc = fo.configure()
>    >>> fc.weight = 'bold'
>    >>> nf = tkFont.Font(b, **fc)
>    >>> b.configure(font=nf, text="Bold Button")
>    >>> b.pack()
>
>You can also find the available "font families":
>    >>> tkFont.families(b)
>    ('nimbus roman no9 l', 'arial black', 'clearlyu devangari extra', ...
>I'm not sure what use this is:
>    >>> tkFont.names(b)
>    ('font136858972', 'font136997436')
>
>Jeff
>
>  
>



More information about the Tkinter-discuss mailing list