how to display unicode in a Label in Tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ali

    #1

    how to display unicode in a Label in Tkinter

    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.
  • Eric Brunel

    #2
    Re: how to display unicode in a Label in Tkinter

    Ali wrote:[color=blue]
    > 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.[/color]

    Just put it in a Unicode string or in a raw string encoded in UTF-8 and you
    should be going:
    [color=blue][color=green][color=darkred]
    >>> from Tkinter import *
    >>> root = Tk()
    >>> s = 'àéèù: ça marche!'
    >>> u = unicode(s, 'iso8859-1')
    >>> Label(root, text=u).pack()[/color][/color][/color]

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

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

    Comment

    • Ali

      #3
      Re: how to display unicode in a Label in Tkinter

      Eric Brunel <eric_brunel@de spammed.com> wrote in message news:<cfpop0$jl t$1@news-reader5.wanadoo .fr>...[color=blue]
      > Ali wrote:[color=green]
      > > 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.[/color]
      >
      > Just put it in a Unicode string or in a raw string encoded in UTF-8 and you
      > should be going:
      >[color=green][color=darkred]
      > >>> from Tkinter import *
      > >>> root = Tk()
      > >>> s = 'àéèù: ça marche!'
      > >>> u = unicode(s, 'iso8859-1')
      > >>> Label(root, text=u).pack()[/color][/color]
      >
      > (The code above supposes your default encoding is iso8859-1, a.k.a latin-1;
      > otherwise, you can do: s = '\xe0\xe9\xe8\x f9: \xe7a marche!')
      >
      > HTH[/color]

      So how I write in Arabic?

      Comment

      • Eric Brunel

        #4
        Re: how to display unicode in a Label in Tkinter

        Ali wrote:[color=blue]
        > Eric Brunel <eric_brunel@de spammed.com> wrote in message news:<cfpop0$jl t$1@news-reader5.wanadoo .fr>...
        >[color=green]
        >>Ali wrote:
        >>[color=darkred]
        >>>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.[/color]
        >>
        >>Just put it in a Unicode string or in a raw string encoded in UTF-8 and you
        >>should be going:
        >>[color=darkred]
        >> >>> from Tkinter import *
        >> >>> root = Tk()
        >> >>> s = 'àéèù: ça marche!'
        >> >>> u = unicode(s, 'iso8859-1')
        >> >>> Label(root, text=u).pack()[/color]
        >>
        >>(The code above supposes your default encoding is iso8859-1, a.k.a latin-1;
        >>otherwise, you can do: s = '\xe0\xe9\xe8\x f9: \xe7a marche!')
        >>
        >>HTH[/color]
        >
        >
        > So how I write in Arabic?[/color]

        The general answer would be to use the unicode codes for the various characters
        you use, e.g.:
        [color=blue][color=green][color=darkred]
        >>> from Tkinter import *
        >>> root = Tk()
        >>> Label(root, text=u'\u0646') .pack()[/color][/color][/color]

        If you want to do that, you'll find
        http://www.unicode.org/versions/Unic...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

        Comment

        • Matthias Huening

          #5
          Re: how to display unicode in a Label in Tkinter

          alikakakhel3@ho tmail.com (Ali) wrote in
          news:8f17f4bc.0 408161437.2f557 935@posting.goo gle.com:
          [color=blue]
          > Eric Brunel <eric_brunel@de spammed.com> wrote in message
          > news:<cfpop0$jl t$1@news-reader5.wanadoo .fr>...[color=green]
          >> Ali wrote:[color=darkred]
          >> > 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.[/color]
          >>
          >> Just put it in a Unicode string or in a raw string encoded in UTF-8
          >> and you should be going:
          >>[color=darkred]
          >> >>> from Tkinter import *
          >> >>> root = Tk()
          >> >>> s = 'àéèù: ça marche!'
          >> >>> u = unicode(s, 'iso8859-1')
          >> >>> Label(root, text=u).pack()[/color]
          >>
          >> (The code above supposes your default encoding is iso8859-1, a.k.a
          >> latin-1; otherwise, you can do: s = '\xe0\xe9\xe8\x f9: \xe7a
          >> marche!')
          >>
          >> HTH[/color]
          >
          > So how I write in Arabic?[/color]

          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:[color=blue][color=green][color=darkred]
          >>> u = unicode(s, 'iso8859-6')[/color][/color][/color]

          Hope this helps.
          Matthias

          Comment

          • Jeff Epler

            #6
            Re: how to display unicode in a Label in Tkinter

            On Mon, Aug 16, 2004 at 03:37:21PM -0700, Ali wrote:[color=blue]
            > So how I write in Arabic?[/color]

            You're unlikely to get anything satisfactory. Tk doesn't do
            right-to-left text layout, and it does character-at-a-time drawing which
            means you won't get the proper linking between the characters.

            I don't know if this bad news is out of date by now, but it certainly
            applies to Tk 8.2 and 8.3 on Unix and Windows.

            Here's some related advice from the tcl/tk wiki:

            but you have to have the stomach to read tcl code.

            Jeff

            -----BEGIN PGP SIGNATURE-----
            Version: GnuPG v1.2.4 (GNU/Linux)

            iD8DBQFBIfI7Jd0 1MZaTXX0RAu0/AJ4ud3E6IpkbcRO 3iFsV+Uj2shAd2A CfZmxC
            j4XXU9v+wDApEj+ +b5PQ2rI=
            =2KEB
            -----END PGP SIGNATURE-----

            Comment

            Working...