Help with Unicode? in Tkinter?

Sheila King sheila at spamcop.net
Sat Sep 1 15:50:19 EDT 2001


OK, my son and I are writing him a drill program for practicing his
French vocabulary. Basically, a textfile contains English/French word
pairs. His program supplies one of the words in the pair, he is supposed
to enter the other.

Of course, the French alphabet uses some characters not available in US
7-bit ASCII. For example:
çèéÇÈÉ

Our program uses Tkinter. I would like to be able to display characters
such as the ones above in Tkinter Lables, Entry boxes and Textareas. Is
this possible?

I have figured out how to use the codecs and unicode modules to write
and read characters such as the above to a text file. However, in an
interactive session in IDLE (which is a Tkinter program), I cannot get
such characters to display in the Textarea of the IDLE session.

When I try, I get things like this:
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> print u'\xe7'
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in ?
    print u'\xe7'
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> ord(u'\xe7')
231
>>> print unichr(231)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in ?
    print unichr(231)
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> 

The ASCII encoding error: ordinal not in range(128) tells me that
Tkinter is configured to only accept values in that range (the typical
7-bit ASCII code). I need to extend it to the latin-1 charset.

Is there some way to do this in a Tkinter program? (I don't really care
if I can accomplish it in IDLE, per se, as long as I can accomplish it
in the Tkinter app we are writing.) We are using win32 platforms
(win98/win2000).

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list