EasyGui and Unicode

As Python 3 is now more Unicode-friendly, I’m getting more and more enquiries about using EasyGui with Unicode.

First, of course, folks are interested in using EasyGui to display messages in non-Latin character sets.  They are interested in whether EasyGui can display Unicode, and also in what tools are available for writing Python code that contains Unicode text.

In addition, there is interest in getting user input in non-Latin character sets.  Some developers are interested in support for bidirectional (“bidi”) languages such as Hebrew and Arabic, which normally read from right to left but allow the embedding of left-to-right text for things like numbers and quotations from left-to-right languages. It was in connection with bidi languages that I recently posted on how to reverse a string in Python 3.

EasyGui uses Tkinter (which uses Tk and Tcl) for its graphical displays. (Tkinter and Tk are included in the standard Python distribution, which is why EasyGui uses Tkinter.) So questions about EasyGui’s Unicode capabilities are essentially questions about Tkinter’s (and Tk’s) Unicode capabilities.

Unfortunately, the news about Tkinter’s Unicode capabilities is not good. Tk and Tcl weren’t designed with Unicode in mind, and certainly not with Unicode data entry in mind.

Tkinter (and therefore Easygui) can display non-Latin Unicode characters if they are sent in from a calling application.  The problem here is how to write the Python code for the application. One person I know uses the gedit editor on Linux to do it;  it seems that gedit has pretty good Unicode support.

I don’t know about Unicode support in the popular Python IDE’s. This post suggests that SPE might provide support for Unicode. (If you have information about Python IDEs and their support for Unicode, it would be great if you could comment on this post with that information.)

But entering user input into Tkinter and EasyGui is a problem. As far as I know, there is no way to tell a Tkinter data-entry widget about the incoming encoding. So about the best you can do is to use (say) gedit to create the text that you want, and then copy and paste the text into the EasyGui data-entry widget. Needless to say, this is highly unsatisfactory.

According to this post, as of 2008-07-03 “Tk has no bidi facilities yet”. So Tk, and therefore Tkinter, and therefore EasyGui, do not support bidi languages, and it doesn’t appear likely that bidi support will be coming any time soon. So Arabic and Hebrew users are just plain out of luck.

I’d like to be able to tell you which Python GUI packages do provide good Unicode support; then I could recommend wxPython or PyQT or something as an alternative to EasyGui. But I honestly don’t know about the level and quality of Unicode support in other GUI packages. (If you have information on this topic, it would be great if you could comment on this post with that information.)

This entry was posted in Uncategorized. Bookmark the permalink.

9 Responses to EasyGui and Unicode

  1. David Boddie says:

    PyQt exposes all of Qt’s i18n features, including support for bidirectional languages. Qt has its own classes for strings, codecs and text streams, so there’s some overlap between what Python provides and what Qt provides.

    See this page for some fairly detailed information about how Unicode is handled by PyQt:

    http://www.riverbankcomputing.com/static/Docs/PyQt4/pyqt4ref.html#python-strings-qt-strings-and-unicode

  2. Jason Fruit says:

    PyGTK displays and accepts Unicode well, and I know it handles Hebrew, pointed and not, just fine.

  3. But entering user input into Tkinter and EasyGui is a problem. As far as I know, there is no way to tell a Tkinter data-entry widget about the incoming encoding. So about the best you can do is to use (say) gedit to create the text that you want, and then copy and paste the text into the EasyGui data-entry widget. Needless to say, this is highly unsatisfactory.
    I really don’t know about Tkinter’s bidirectionality, but I have no reason to doubt you.

    However, I cannot understand this paragraph of yours. What do you mean “there is no way to tell Tkinter… …about the incoming encoding.”? This is an issue of the desktop environment. One switches to a keyboard input language and then enters text to the Entry/Text widget; it works (verified by me on Windows and Ubuntu/Gentoo, at least). If you want to send data directly to the widget, and you don’t want to send it as Unicode strings or if you don’t use the Tkinter layer, just send your data encoded as UTF-8.

    Please elaborate. Bidirectionality apart, Tkinter is *very* Unicode capable.

    • Uldis says:

      I also encountered problems with Tkinter and Unicode.

      Just as the author write, Unicode entry is a problem. With default Python on Mac OS X, a Tkinter app crashes with NSRangeException as soon as a non-Latin char is entered in a tk.Entry field.

      If using a MacPorts Python installation (and Tkinter using X Windows) the application does not crash, but the characters that appear in the Entry box are in a wrong encoding.

      Would be good if I figured out how to [at least] prevent Tkinter app from crashing when a non-Latin char is entered into the Entry widget.

  4. Matta says:

    Use of bidirectional languages on Windows is not a problem. The underlying OS presents the language(s) in the correct direction, and links characters that must be linked.
    It still does not work on Linux, however.

  5. Gonzo Bumm says:

    I just downloaded easygui and fileopenbox explodes – could we in 2013 please finally get finished with these annoying unicode trouble, i feel like 1997 or something. If it is easy to fix please add that fix ASAP. Also it would be great to have that updated version on pip then.
    I really totally respect and love your effort, but these unicode bombs all over the python libs are a real PITA.

  6. I’m more than happy to uncover this web site. I want to to thank you for your time due to this fantastic
    read!! I definitely appreciated every par of it and I have you book
    marked tto look at new information in your blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s