ericc
ericc

Reputation: 781

Fonts management on Linux for Python and Tkinter

I have written an application in Python2.7/Tkinter. I have 2 Linux machines:
1 Xubuntu with python 2.7.4 1 CentOS (5.2) with python 2.7.1 (Unfortunately, and before someone ask, I can't upgrade this machine)

I connect on both machine from my WindowsXP laptop through SSH and I export the display. Xming is installed on the windows machine as X server. The script is exactly the same on both machine (shared drive mounted on both machine).

In the script I have :

# show which fonts the system know 
print tkFont.families()
# configure the default font
default_font = tkFont.nametofont("TkDefaultFont")
default_font.configure(family="Liberation Sans", size="10")
master.option_add("*Font", default_font)

The fonts "Liberation" are installed on both Linux machine and in Xming (and configured).
In the application I used the grid manager, so the font have a big impact on the resulting interface.

When I launch the application from Xubuntu:

When I launch the application from CentOs:

I scratch my head since this morning on this, I even copied the liberation*.ttf files from Xubuntu to all other machines, without success

How can I suppress this difference between the 2 machines, that my interface look the same on both ?

Any help will be greatly appreciated

Upvotes: 1

Views: 2303

Answers (1)

nim
nim

Reputation: 2441

At a guess, your tk installation server-side relies on the X Core fonts subsystem to render fonts (this is why it shows xming fonts).

This subsystem has been replaced by fontconfig a long time ago (but tk was very late in switching). Centos 5.2 is probably old enough its tk version still relies on the X Core fonts subsystem. However, Fedora and Red Hat stopped exposing system truetype fonts as X Core fonts quite a long time ago (it was breaking legacy applications).

So your solution is :

– either upgrade to a tk that can use fontconfig (or reconfigure it to use fontconfig) : this way it will see the modern fonts installed in Centos, including Liberation http://wiki.tcl.tk/9015

– or, do all the legacy magic to expose liberation font in xfs (mkfontdir, and friends, as documented in all pre-2000 Linux font howtos). ANd pray that does not break something else, the X core font system is not particularly robust.

https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-x-fonts.html

Mid term you'll had to do it the fontconfig way anyway since x core fonts are on the way out (it was already the case when RHEL 5 was released circa 2007).

Upvotes: 1

Related Questions