[UNICODE] Tkinter and Unicode->ISO-8859-1 issues

Eric Brunel eric.brunel at pragmadev.com
Fri Jan 11 05:31:51 EST 2002


Hi,

Got the same problem, and you got it right: when get'ting the contents of
Tkinter widgets, you always get text in UTF-8 encoding. It's quite simple to
encode it back into Latin1, but I had to do it "by hand" everytime I wrote
the file. To convert UTF-8 into Latin1 encoding, just do:
text = unicode(text, "UTF-8").encode('iso8859-1')
And just hope the user's of your tool won't ever type a character that isn't
in the Latin1 character set, or you'll get a nice exception... :-)

HTH
 - eb -

"Valter Ferraz Sanches" <> a écrit dans le message news:
ac6cc0a7.0201100756.372c05ec at posting.google.com...
> Hello everybody!
>
> I´m writing a small app that opens and writes text files (is a kind of
> rolodex) in Python, using the Tkinter(face).
>
> The fact is: if I open the file at first with the string "áéíóú" for
> example, and try to write again the same string or other that contain
> latin1 stuff, I´m not capable of reading the text file correctly (I
> see the Unicode stuff broken in one byte chars; this way, "ç" becomes
> "ç" and so on) in other apps, as "cat" or "emacs", though my app can
> show the chars corretly. I noticed that IDLE-0.8 and fetchmailconf
> (when they can save the file) have the same problem.
>
> I think it´s a problem between Tcl (which passes UTF-8) and Python,
> because the bug (feature?) occurs only when get'ting the contents of
> the Text and Entry widgets.
>
> Does anybody have an idea to fix the problem, or, at least, make me
> understand why does it happens? Ignacio?
>
> Thanks for your attention. I would be glad if a copy could be sent to
> me, because I won´t connect for the 5 next days (i´m going to travel).
>
> Thanks again.
>
> Valter Ferraz Sanches <vfs at mail.com>





More information about the Python-list mailing list