[Tkinter-discuss] tk 8.3 and unicode

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Thu May 26 11:22:18 CEST 2005


Hi all,

Another possibly silly question.....

My prodcution machines are stuck at python2.2 and tk 8.3
and *I* have a problem with the following code:-

import codecs
import Tkinter

root=Tkinter.Tk()

var = Tkinter.StringVar()

e = Tkinter.Entry(root, textvariable=var)
e.pack()


var.set(u"\xa3  \xa3")

#~ f = codecs.open("ce.tst", "w", "utf-8")
#~ f.write(var.get())
#~ f.close()


print  repr(var.get())

root.mainloop()


The GUI shows up and is correct, however when I un-comment the three
save to file lines it fails with:

UnicodeError: ASCII decoding error: ordinal not in range(128)

Indeed when I look at the printed output from the code is shows:-

'\xc2\xa3  \xc2\xa3'

rather than what I put into that variable.....  I assume this is a
feature of tk 8.3 - i've tested on py2.3+tk8.4 and py2.4+tk8.5 and
both those version *just work*

is there any get around?


Cheers
Martin









More information about the Tkinter-discuss mailing list