how to display unicode in a Label in Tkinter
Matthias Huening
mhuening at zedat.fu-berlin.de
Tue Aug 17 03:51:56 EDT 2004
alikakakhel3 at hotmail.com (Ali) wrote in
news:8f17f4bc.0408161437.2f557935 at posting.google.com:
> 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?
For Arabic you'll probably use Unicode (in which case you can just use
the text in Tkinter) or you'll have tekst encoded as 'iso8859-6'. Then
you have to use something like:
>>> u = unicode(s, 'iso8859-6')
Hope this helps.
Matthias
More information about the Python-list
mailing list