Help with Unicode? in Tkinter?

Ignacio Vazquez-Abrams ignacio at openservices.net
Sun Sep 2 00:18:54 EDT 2001


On Sat, 1 Sep 2001, Sheila King wrote:

> 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.

I think that the problem is that you're using unicode strings instead of just
strings. Here's what I got under Idle (Python 1.5.2 though):

---
>>> print string.join(map(chr, range(160, 256)), '')
 ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
>>>
---

Try using just chr() instead of unichr().

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list