I have two Python installations on my Debian Sid notebook, ⑴ the system's Python (v.2.7) with a little bunch of utility packages (including Tkinter
) and ⑵ Anaconda's Python 3.
It is easy to see which (well, here how many...) fonts are available for the two Python distributions.
Python 2
>>> from Tkinter import Tk
>>> from tkFont import families
>>> Tk(); available = families() ### Tk() is needed to have a running tcl interpreter
<Tkinter.Tk instance at 0x7f977bcbfb90>
>>> len(available)
3011
Python 3
>>> from tkinter import Tk
>>> from tkinter.font import families
>>> Tk() ; available = families()
<tkinter.Tk object .>
>>> len(available)
68
It seems to me that Anaconda's tkinter
only looks at the basic X fonts that came with the distributionsee edit below.
Do you know a procedure to, alternatively
- let Anaconda's
tkinter
know of the system fonts (preferred alternative) or
- install a few fonts in the Anaconda's tree so that
tkinter
can use them?
tia
Edit the fonts available to Anaconda are indeed system fonts, but only the fonts that are known to xfontsel
, i.e., the fonts in the font path that can be manipulated using xset
.
I tried the following
$ cd ~/.fonts ; mkfontscale ; mkfontdir ; xset fp+ `pwd`
and xfontsel
showed about 30 more font families. Checking with Python 3 I verified that only two font families were added to the list of available fonts (namely 'go'
and 'gomono'
— no 'consolas'
etc) and producing a label
...
r = Tk() ; Label(r, text="Go Mono", font=('gomono', 24)).pack()
with Python 2 and Python 3 succeeded in both cases, but Debian's Python showed a nice antialiased text while the other was a (rough) bitmap rendition.
So, in a sense, I have partially answered my question, but
- not every font family, as shown by
xfontsel
, was taken up by tkinter
- even for the very few that were recognized, the rendition leaves too much to be desired...
and I'd like to read a better, more useful answer.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…