Antialiased fonts in Tk Tkinter in Ubuntu 8.04

27 views
Skip to first unread message

Terry Brown

unread,
Apr 4, 2008, 11:29:18 AM4/4/08
to leo-editor
I don't advise anyone to try and get anti-aliased fonts working in
Linux (Ubuntu) by compiling python against Tk8.5, there's too much risk
of messing things up. But I think I have it working now, so if you
really want to...

Note: I upgraded to 8.04 because my attempts to get this working on
7.10 had messed that install up so badly I decided to abandon it.

Install 8.04, and then, before you do anything else much:

- install (using synaptic) Tk8.5 and its dev package

- download Python 2.5.2 tar ball configure it like this:

./configure --prefix=/usr --enable-unicode=ucs4
make
make install

The ucs4 bit is, I think, the magic bullet. By default the tar ball
uses ucs2, but ubuntu uses ucs4, so all ubuntu's packages break, at
least those with compile C code (.so) components. ucs2/ucs4 are
pythons approach to utf8/utf16 encodings.

- cd /usr/bin; rm python; ln -s python2.5 python

The tar ball install hardlinks these two files, and the ubuntu system
checks to make sure that /usr/bin/python is a *symbolic* link to
python2.5

Packages which ubuntu thinks depend on tk8.4, like PIL, ImageTk, tkcvs
etc., you will need to build from source, but others should work ok.

Or just wait for python 2.6/3.0 :-)

Cheers -Terry

Edward K. Ream

unread,
Apr 5, 2008, 8:59:21 AM4/5/08
to leo-e...@googlegroups.com
On Fri, Apr 4, 2008 at 10:29 AM, Terry Brown <terry_...@yahoo.com> wrote:

I don't advise anyone to try and get anti-aliased fonts working in
Linux (Ubuntu) by compiling python against Tk8.5, there's too much risk of messing things up.  But I think I have it working now, so if you really want to...

[big snip]

Or just wait for python 2.6/3.0 :-)

Thanks for these instructions.  I do hope Python fixes the recent major tkinter problems soon.

Edward

Ville M. Vainio

unread,
May 12, 2008, 1:28:10 PM5/12/08
to leo-e...@googlegroups.com
On Fri, Apr 4, 2008 at 6:29 PM, Terry Brown <terry_...@yahoo.com> wrote:

> I don't advise anyone to try and get anti-aliased fonts working in
> Linux (Ubuntu) by compiling python against Tk8.5, there's too much risk
> of messing things up. But I think I have it working now, so if you
> really want to...
>
> Note: I upgraded to 8.04 because my attempts to get this working on
> 7.10 had messed that install up so badly I decided to abandon it.
>
> Install 8.04, and then, before you do anything else much:
>
> - install (using synaptic) Tk8.5 and its dev package
>
> - download Python 2.5.2 tar ball configure it like this:
>
> ./configure --prefix=/usr --enable-unicode=ucs4
> make
> make install
>
> The ucs4 bit is, I think, the magic bullet. By default the tar ball
> uses ucs2, but ubuntu uses ucs4, so all ubuntu's packages break, at
> least those with compile C code (.so) components. ucs2/ucs4 are
> pythons approach to utf8/utf16 encodings.
>


>


> Packages which ubuntu thinks depend on tk8.4, like PIL, ImageTk, tkcvs
> etc., you will need to build from source, but others should work ok.
>
> Or just wait for python 2.6/3.0 :-)
>
> Cheers -Terry

Just a data point - I did this on Ubuntu 8.04, python 2.6a3, and trunk
leo, and leo works & has antialiased fonts (albeit with too large size
by default). It's probably safer to build python 2.6 than 2.5, which
may have a slight chance of messing with system python 2.5. Obviously,
you should delete the link from python -> python2.6, and invoke leo
manually with python 2.6 for extra safety.

And, you should probably install it under normal /usr/local prefix
rathen than /usr.

I.e. don't do this:

> - cd /usr/bin; rm python; ln -s python2.5 python
>
> The tar ball install hardlinks these two files, and the ubuntu system
> checks to make sure that /usr/bin/python is a *symbolic* link to
> python2.5

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'

Edward K. Ream

unread,
May 13, 2008, 2:37:05 PM5/13/08
to leo-e...@googlegroups.com


On Mon, May 12, 2008 at 12:28 PM, Ville M. Vainio <viva...@gmail.com> wrote:

Thanks for these instructions re anti-aliased fonts.  As you know, I've been obsessed with key bindings lately, but I plan to get around to rescuing the ubuntu version of Leo soon...

Edward

Edward K. Ream

unread,
May 18, 2008, 2:30:16 PM5/18/08
to leo-e...@googlegroups.com
On Mon, May 12, 2008 at 12:28 PM, Ville M. Vainio <viva...@gmail.com> wrote:

On Fri, Apr 4, 2008 at 6:29 PM, Terry Brown <terry_...@yahoo.com> wrote:

>  I don't advise anyone to try and get anti-aliased fonts working in
>  Linux (Ubuntu) by compiling python against Tk8.5, there's too much risk
>  of messing things up.  But I think I have it working now, so if you
>  really want to...

I would encourage people to take the risk.  Before I understood that Python is essential to ubuntu operation I actually dis-installed all of Python, trying to get back to a fixed state.  I lost the entire gui, so I ended up in a raw text mode. But I was able to reinstall it all using apt-get.  Don't remember the details, but google (on another machine) was my friend.

Edward

Terry Brown

unread,
May 20, 2008, 3:27:07 PM5/20/08
to leo-e...@googlegroups.com
An addendum, I just switched to a new machine and for some reason when
compiling PIL had to change two occurrences of '#include "tk.h"' to
'#include "tcl8.5/tk.h"', don't remember having done that before.

The gtk interface will fix all this... :-)

Cheers -Terry

Edward K. Ream

unread,
May 21, 2008, 9:10:56 AM5/21/08
to leo-e...@googlegroups.com
On Mon, May 12, 2008 at 12:28 PM, Ville M. Vainio <viva...@gmail.com> wrote:



>  Packages which ubuntu thinks depend on tk8.4, like PIL, ImageTk, tkcvs
>  etc., you will need to build from source, but others should work ok.

This is a nightmare.  Googling download ImageTk brings me to
http://packages.ubuntu.com/hardy/python/python-imaging-tk

If you can understand this gobbledygook  you understand far more than I do.

Python simply must clean up its act.

Hmm.  I just had a thought.  Could I (and all of Leo's users) bypass these problems by using ipython?

Edward

Ville M. Vainio

unread,
May 21, 2008, 10:01:04 AM5/21/08
to leo-e...@googlegroups.com
On Wed, May 21, 2008 at 4:10 PM, Edward K. Ream <edre...@gmail.com> wrote:

> This is a nightmare. Googling download ImageTk brings me to
> http://packages.ubuntu.com/hardy/python/python-imaging-tk
>
> If you can understand this gobbledygook you understand far more than I do.

You don't need to build separate imageTk, it seems to come with PIL
source package. I put

> Hmm. I just had a thought. Could I (and all of Leo's users) bypass these
> problems by using ipython?

No, that won't help. The best bet is still to:

- Install tk 8.5

- build python 2.6

- Install PIL source package to python 2.6 (python2.6 setup.py
install); the only change to setup.py needed is:

TCL_ROOT = "/usr/include/tcl8.5"

Edward K. Ream

unread,
May 21, 2008, 10:03:00 AM5/21/08
to leo-e...@googlegroups.com

On Wed, May 21, 2008 at 8:10 AM, Edward K. Ream <edre...@gmail.com> wrote:

On Mon, May 12, 2008 at 12:28 PM, Ville M. Vainio <viva...@gmail.com> wrote:

>  Packages which ubuntu thinks depend on tk8.4, like PIL, ImageTk, tkcvs
>  etc., you will need to build from source, but others should work ok.

This is a nightmare.  Googling download ImageTk brings me to
http://packages.ubuntu.com/hardy/python/python-imaging-tk

If you can understand this gobbledygook  you understand far more than I do.

Actually, just installing Python2.5.2 as Terry described solved my problems with fonts.  Notes:

- Here is an excellent how-to for installing packages on ubuntu from sources:

https://help.ubuntu.com/community/CompilingEasyHowTo

For example, it describes the tar args needed, where to put stuff, etc.

- The procedure Terry describes will install from /usr/local/src to /usr/bin

- I have no idea where the links files are.  But since Python works it should allow Ubuntu to restart even if ubuntu starts using the newly-installed python.  And indeed, restarting Ubuntu went well.

- I changed 'leo' alias so it explicitly uses /usr/bin/python2.5.  That should be enough to guarantee I always use the newly-installed python.

Hope this helps everyone.

BTW, I am now seeing the get_focus crash.  The workaround will probably be to ignore any exception...

Edward

Ville M. Vainio

unread,
May 21, 2008, 10:22:51 AM5/21/08
to leo-e...@googlegroups.com
On Wed, May 21, 2008 at 5:03 PM, Edward K. Ream <edre...@gmail.com> wrote:

> - I have no idea where the links files are. But since Python works it
> should allow Ubuntu to restart even if ubuntu starts using the
> newly-installed python. And indeed, restarting Ubuntu went well.

I'm still a bit concerned about this approach, since it messes with
the "system" python. What will happen when security fixes for python
come up? What about the python packages you install with apt-get later
on, will they be available normally?

Of course all this "may work", but caution should be advised.

Terry Brown

unread,
May 21, 2008, 10:28:30 AM5/21/08
to leo-e...@googlegroups.com
On Wed, 21 May 2008 08:10:56 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> > > Packages which ubuntu thinks depend on tk8.4, like PIL, ImageTk,
> > > tkcvs etc., you will need to build from source, but others should
> > > work ok.
> >
> This is a nightmare. Googling download ImageTk brings me to
> http://packages.ubuntu.com/hardy/python/python-imaging-tk

I guess I don't really see the problem. If you're not aiming for
anti-aliased fonts, you should be able to get all the required imports
by:

sudo apt-get install python-imaging-tk python-imaging tk8.4 python-tk

If leo was a .deb package you'd just install that and it would tell you
about the dependencies and ask for permission to install them.

It feels to me like it's time to suddenly veer completely off topic.

I recently started playing with Virtual Box from Sun, and have
installed and run Ubuntu 8.04 under Windows XP, and Windows XP under
Ubuntu 8.04. A virtual Ubuntu 8.04 (under Ubuntu 8.04 would be fine)
would be a good way of maintaining a virgin Ubuntu install to test Leo
installation - Virtual Box has a snapshot feature so you only need to
do the initial install of Ubuntu once, and thereafter you can return to
a clean state.

There are other virtualization solutions, but Virtual Box is very easy
to use, which I think recommends it for this type of virtualization
application.

Cheers -Terry

Terry Brown

unread,
May 21, 2008, 10:41:16 AM5/21/08
to leo-e...@googlegroups.com
On Wed, 21 May 2008 17:22:51 +0300
"Ville M. Vainio" <viva...@gmail.com> wrote:

> > - I have no idea where the links files are. But since Python works
> > it should allow Ubuntu to restart even if ubuntu starts using the
> > newly-installed python. And indeed, restarting Ubuntu went well.
>
> I'm still a bit concerned about this approach, since it messes with
> the "system" python. What will happen when security fixes for python
> come up? What about the python packages you install with apt-get later
> on, will they be available normally?
>
> Of course all this "may work", but caution should be advised.

You have a point. So far I've found that all other python packages
work, the key to getting that to happen was compiling python from
source with the --enable-unicode=ucs4 flag as the default is ucs2 but
ubuntu uses ucs4. Packages linked against Tk8.4 have to be compiled
from source.

You're right about security fixes for python - you'd have to make a
point of recompiling from the latest source to get those I guess.

Here's my original how to for anti-aliased fonts
with Ubuntu 8.04,

http://www.mail-archive.com/leo-e...@googlegroups.com/msg00320.html

with the addendum that when I moved to a new machine just a few days
ago I found I couldn't get PIL to compile from source without changing
to occurrences of '#import "tk.h"' to '#import "tcl8.5/tk.h"'.

I think the real solution is for leo and python to move to gtk - I
understand how the relationship between python and tk evolved, but I
can't see how tk can sensibly evolve to be a "modern" gui toolkit
without basically duplicating gtk at that point.

gtk support is good for linux / windows / mac os X, but probably weaker
for some of the other unixen out there on which tk works well - so
that's a problem. On the other hand tk doesn't have to go away, and
hopefully python 2.6 / 3.0 will be linked against tk 8.5 in future
distros anyway, so we're really just experiencing growing pains.

At least open source gives us the tools to fix things.

Cheers -Terry

Edward K. Ream

unread,
May 21, 2008, 12:08:48 PM5/21/08
to leo-e...@googlegroups.com
On Wed, May 21, 2008 at 9:28 AM, Terry Brown <terry_...@yahoo.com> wrote:

On Wed, 21 May 2008 08:10:56 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> > >  Packages which ubuntu thinks depend on tk8.4, like PIL, ImageTk,
> > > tkcvs etc., you will need to build from source, but others should
> > > work ok.
> >
> This is a nightmare.  Googling download ImageTk brings me to
> http://packages.ubuntu.com/hardy/python/python-imaging-tk

I guess I don't really see the problem.  If you're not aiming for
anti-aliased fonts, you should be able to get all the required imports
by:

 sudo apt-get install python-imaging-tk python-imaging tk8.4 python-tk

I see.  I was forgetting apt-get.  Thanks.

Edward
Reply all
Reply to author
Forward
0 new messages