Handling letters with accents

Martyn Quick mrq at for.mat.bham.ac.uk
Fri Feb 7 20:30:13 CET 2003

On Fri, 7 Feb 2003, Eric Brunel wrote:
> > 
> > To give a basic example (which illustrates the problem on a Windows98
> > machine, and probably on later versions of Windows too)...
> > 
> > import Tkinter
> > root = Tkinter.Tk()
> > var = Tkinter.StringVar()
> > Tkinter.Entry(root, textvariable=var).pack()
> > 
> > Typing CTR+ALT+u into the entry and then calling
> > 
> > print var.get()
> > 
> > produces a small amount of garbage that looks nothing like the u with
> > acute accent that appears in the entry box.
> In fact, it *is* the accented u that you typed in the entry, except it appears 
> to be coded in UTF-8, which is the base Tk encoding. Considering the default 
> encoding for the console where your print statements go is certainly the 
> "standard" latin1 encoding, doing:
> print unicode(var.get(), 'utf-8').encode('iso8859-1', 'replace')
> instead of just "print var.get()" should do what you want.

Thanks very much for the reply.  This doesn't quite do what I expected -
it prints a dot instead of the accented character - might it be a
different encoding than expected being used for my DOS box display?


Dr. Martyn Quick  (Research Fellow in Pure Mathematics)
University of Birmingham, Edgbaston, Birmingham, UK.

More information about the Python-list mailing list