how to display unicode in a Label in Tkinter

Eric Brunel eric_brunel at despammed.com
Mon Aug 16 03:54:48 EDT 2004


Ali wrote:
> I was wondering how one would go about displaying unicode in a Label
> object in a Tkinter window. I am trying to display text in another
> language. Please help.

Just put it in a Unicode string or in a raw string encoded in UTF-8 and you 
should be going:

 >>> from Tkinter import *
 >>> root = Tk()
 >>> s = 'àéèù: ça marche!'
 >>> u = unicode(s, 'iso8859-1')
 >>> Label(root, text=u).pack()

(The code above supposes your default encoding is iso8859-1, a.k.a latin-1; 
otherwise, you can do: s = '\xe0\xe9\xe8\xf9: \xe7a marche!')

HTH
-- 
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list