how to display unicode in a Label in Tkinter

Eric Brunel eric_brunel at despammed.com
Tue Aug 17 03:46:02 EDT 2004


Ali wrote:
> Eric Brunel <eric_brunel at despammed.com> wrote in message news:<cfpop0$jlt$1 at news-reader5.wanadoo.fr>...
> 
>>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
> 
> 
> So how I write in Arabic?

The general answer would be to use the unicode codes for the various characters 
you use, e.g.:

 >>> from Tkinter import *
 >>> root = Tk()
 >>> Label(root, text=u'\u0646').pack()

If you want to do that, you'll find 
http://www.unicode.org/versions/Unicode4.0.0/bookmarks.html very useful 
(especially section 8 in your case). But it's quite hard to type characters this 
way...

There must be another simpler way, based on the standard encoding used when 
using Arabic characters. But I don't know this encoding, so I cannot help you 
much here. I also don't know how you can input these characters in a computer 
(especially in a source file, where the character flow is from left to right)

So I can only return the question: how do *you* usually input Arabic characters 
in a source file? Knowing that and the encoding you use, putting Arabic text in 
Tkinter labels won't be difficult at all.

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