问题描述
我在Debian Sid笔记本上安装了两个Python安装程序:⑴系统的Python(v.2.7),带有一些实用程序包(包括 Tkinter )和⑵Anaconda Python 3。这两个Python发行版很容易看到哪些(以及这里有多少个)字体可用。 b
Python 2
>>>从Tkinter import Tk
>>> from tkFont import families
>>> TK(); available = families()### Tk()需要有一个正在运行的tcl解释器
< Tkinter.Tk实例在0x7f977bcbfb90>
>>> len(可用)
3011
Python 3
>>> from tkinter import Tk
>>>从tkinter.font导入系列
>>> Tk(); available = families()
>>> len(available)
68
在我看来,Anaconda的 tkinter 仅查看分布式附带的基本X字体 。
你知道一个程序,或者 编辑 Anaconda可用的字体确实是系统字体,但只有 xfontsel 的字体,即字体路径中的字体可以是操作使用 xset 。 我尝试了以下操作:
$ cd〜/ .fonts; mkfontscale; mkfontdir; xset fp +`pwd`
和 xfontsel 显示约30多个字体系列。使用Python 3进行检查我验证了只有两个字体族被添加到可用字体列表中(即'go'和'gomono' - no 'consolas'等等)并生成一个标签
...
r = Tk(); Label(r,text =Go Mono,font =('gomono',24))。pack()
$ b $在这两种情况下,Python 2和Python 3都成功了,但是Debian的Python显示了一个很好的反锯齿文本,而另一个是(粗略的)位图表达式。
,从某种意义上说,我已经部分地回答了我的问题,但不是每个字体家族都有,如 xfontsel所示
- ,被 tkinter
- 占用,即使是被识别的少数,很多人都希望...
我想读一个更好,更有用的答案。 $ b
{tT} kinter 链接到Tk / Tcl解释器,包含在一对DLL中,特别是图形库是 libtk6.0.so 。
大部分 tkinter 不可见的额外字体由Freetype库和Anaconda的<$ c
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' usr / lib / x86_64-linux-gnu / libtk8.6.so | grep freetype
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6(0x00007f0a24597000)
$ ldd miniconda3 / lib / libtk8.6.so | grep freetype
$
我尝试了下面这个可怕的事情b
$ b
$ mv lib / miniconda3 / lib / libtk8.6.so lib / miniconda3 / lib / libtk8.6.sav
$ ln - s /usr/lib/x86_64-linux-gnu/libtk8.6.so lib / miniconda3 / lib / libtk8.6.so
$ ipython
Python 3.6.3 | Anaconda,Inc. | (默认,2017年11月20日,20:41:42)
输入'copyright','credits'或'license'以获取更多信息
IPython 6.2.1 - 增强的交互式Python。输入'?'寻求帮助。
In [1]:从tkinter import Tk,Label;从tkinter.font导入系列
在[2]中:r = Tk(); a = families(); len(a)
Out [2]:328
In [3]:r = Tk(); Label(r,text =Constantia,font =(Constantia,60))。pack()
In [4]:r.mainloop()
/ pre>
最后的想法
- 替换DLL并不是一个干净的解决方案。
- 字体不完全相同。当然,Anaconda有自己的Fontconfig子系统,可能被扫描的目录是不同的,但我对字体数量的差异没有正确的理解。
- 正确的操作方法是说服Anaconda,Inc.建立反对Freetype libtk ,但我不知道如何报告给他们,例如,如果我去我所看到的是关于发行版的信息性文章列表。
更新
Wrto指向3,我通过 Anaconda Inc.和我被告知
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) 3011Python 3
>>> from tkinter import Tk >>> from tkinter.font import families >>> Tk() ; available = families() <tkinter.Tk object .> >>> len(available) 68It seems to me that Anaconda's tkinter only looks at the basic X fonts .
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.
{tT}kinter works linking to a Tk/Tcl interpreter that, loosely speaking, is contained in a couple of DLL, in particular the graphical library is libtk6.0.so.
Most of the extra fonts not seen by tkinter are managed by the Freetype library and Anaconda's libtk6.0.so is not built against Freetype...
$ ldd /usr/lib/x86_64-linux-gnu/libtk8.6.so | grep freetype libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f0a24597000) $ ldd miniconda3/lib/libtk8.6.so | grep freetype $
I've tried the following, horrible thing
$ mv lib/miniconda3/lib/libtk8.6.so lib/miniconda3/lib/libtk8.6.sav $ ln -s /usr/lib/x86_64-linux-gnu/libtk8.6.so lib/miniconda3/lib/libtk8.6.so $ ipython Python 3.6.3 |Anaconda, Inc.| (default, Nov 20 2017, 20:41:42) Type 'copyright', 'credits' or 'license' for more information IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: from tkinter import Tk, Label ; from tkinter.font import families In [2]: r = Tk() ; a = families() ; len(a) Out[2]: 328 In [3]: r=Tk() ; Label(r, text="Constantia", font=("Constantia", 60)).pack() In [4]: r.mainloop()
Final thoughts.
- Substituting the DLL is not a clean solution.
- The fonts are not exactly the same. For sure Anaconda has its own Fontconfig subsystem and possibly the directories that are scanned are different, but I have not a correct understanding of the discrepancy in the number of fonts.
- The correct course of action is to persuade Anaconda, Inc. to build libtk against Freetype, but I don't know how to report to them, e.g., if I go to https://www.anaconda.com/search/issues what I see is a list of informational articles on the distribution.
Update
W.r.to point 3, I contacted via a github issue Anaconda Inc. and I was told
这篇关于使Anaconda的tkinter知道系统字体或为Anaconda安装新的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!