Tkinter: Text widget and fixed-width fonts

Hans Nowak wurmy at earthlink.net
Tue May 28 20:34:41 EDT 2002


Howdy y'all,

I wanted to use the Tkinter Text widget to display text in a fixed
width font, assuming that lines with an equal number of characters
would also have equal length. E.g. a line of "." * 40 should have
the same length as "M" * 40. While this works for "regular"
characters, it doesn't seem to work for special characters (possibly
ASCII >= 128).

Some code:

  font = tkFont.Font(family="FixedSys", size=8)
  text.tag_configure('normal', font=font)

  line1 = chr(252) * 80 + "\n"   
  line2 = "W" * 80 + "\n"
  text.insert(END, line1, 'normal')
  text.insert(END, line2, 'normal')

Now, on my computer, using the FixedSys font, this doesn't display
two lines of equal length. The first one is shorter, but there
are also occasions where it's longer than the line with the Ws.
I tried other fonts as well, including "Courier New", "fixed",
"oemfixed", "systemfixed" etc, but the effect remains the same.

Is there something I can do to make all characters appear in the
same size (like I would expect from a fixed-width font)?

(If it matters, I'm on Win2K, Python 2.2.1.)

Cheers,

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) 
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list