#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0

    Question Tkinter, japanese "kotaeri" input method does not work


    (crossposting note: This has already been posted at python-forum.org, but didn't get any reply so far)

    (Python 2.3.4, OSX 10.4)

    For entering Japanese text, I switch my keyboard to the Japanese "kotoeri" input method (see en.wikipedia.org/wiki/Kotoeri). This doesn't work anymore, when entering the text in a tkinter Entry widget.

    The problems are not the characters itself. I can switch the keyboard schema to, say, Greek, and happily enter Greek characters. I can type a Japanese text in an application outside of tkinter (Terminal command line, text editor,...), copy it and paste it into the Entry widget. This all works fine. It is just that I can't type the Japanese text directly into the widget. It is as if the "Kotoeri" input handler is bypassed.

    I googled for this problem, and while I didn't find anything special for the Mac, I found one user complaining a very similar problem on Microsoft Windows, where also an input method akin to Kotoeri exists. The culprit in this case was a bug in the Tk libraries.

    Is there a similar, known bug in the Tk libraries for this OSX version too?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    492
    Rep Power
    33
    You would have to specify a Japanese font when creating the Entry widget so it has access to the characters to display. This code will tell you what fonts Tkinter can find (may be different from the fonts the system uses), (you can Google for the difference between font families and font names but it really doesn't matter as long as it is found). Please provide some sample code to get additional help.
    Code:
    ## a very basic font display
    
    try:
        import Tkinter as tk     ## Python 2.x
    except ImportError:
        import tkinter as tk     ## Python 3.x
    import tkFont
    top = tk.Tk()
    
    print "------------font families" +"-"*30
    font_tuple = tkFont.families()
    for each_font in font_tuple :
        print each_font
    
    print "------------font names" +"-"*30
    font_tuple = tkFont.names()
    for each_font in font_tuple :
        print each_font
    Last edited by dwblas; November 10th, 2013 at 04:37 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0
    > You would have to specify a Japanese font when creating the Entry widget so it has access to the characters to display.

    No, that's not the problem. The widget can display Japanese text without problem. Actually, I never specify any font for the widgets, and the display all characters. That's the great thing with Unicode.

    I guess the widget somehow bypasses the input method of the keyboard driver, and that's why kotoeri doesn't work here. The question is, how can I make it work?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    492
    Rep Power
    33
    No one wants to sit around and guess what code you are trying so this will be my last post. You may be entering characters that are not in the range of the encoding you are using. If you are using UTF-8 (we don't know) then you may be trying to enter characters in the UTF-16 range, etc.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0
    Originally Posted by dwblas
    No one wants to sit around and guess what code you are trying so this will be my last post. You may be entering characters that are not in the range of the encoding you are using. If you are using UTF-8 (we don't know) then you may be trying to enter characters in the UTF-16 range, etc.
    Sorry if I was unclear with this. I do NOT specify any encoding by myself. My understanding was, that on the operating system I'm using (OSX 10.4) the encoding is always some Unicode.

    However, I didn't consider that the encoding used is a problem - after all, the entry widget happily displays all Japanese characters I need. I can also copy and paste (from, say, the Terminal command line) the Japanese text perfectly fine into the entry field. The problem is that the input method (Kotoeri) does not work in the entry widget. If it really were a problem with wrong encoding, my widgets would not show any Japanese text correctly - or am I wrong here?

    My guess was that the Tkinter Entry widget bypasses Kotoeri. Maybe I draw the wrong conclusion, but at least it looks like this.

    For example, when I enter the letters RE followed by a space in the entry field, it just displays "RE ", while the "usual" behaviour would be to show the letter れ, plus a selection box which would allow me to choose alternative spellings, such as レ or 列. Leaving the encoding issue aside for a moment, the fact that the selection box doesn't open automatically, is a sign that Kotoeri is not used here.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0

    REASON FOUND (Tkinter, japanese "kotaeri" input method does not work)


    I finally found explanations (for example here: http://comments.gmane.org/gmane.comp.lang.tcl.mac/3594) for my problem:

    The older Tk versions don't support the Japanese Input method on OSX yet. In my case, it is Tk 8.4, which to the best of my knowledge is the most recent which can be used with Python 2.3.4.

    I note I found on this subject (http://www.ne.jp/asahi/kazuo/sasagawa/eng.html, see the explanations of cocoEdit) seems to suggest that even Tk 8.5 and 8.6 don't have it yet.

    Several sites suggest for this reason to not use Tk as a GUI, if Japanese text needs to be entered :-(
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0
    ADDED INFORMATION:

    I found that it doesn't work better on newer Python versions either (on OSX). I had a chance to get my hands on a Windows 7 machine, and kotoeri works perfectly well with my program (using Python 2.7).

    As for OSX, I also tested 10.6 (Snow Leopard) in addition to Tiger, with Python 2.6 and 3.0, and in both cases Kotoeri does NOT work in Tkinter Entry widgets.

    To sum up: It works on Windows 7, but not on OSX (at least not up to Snow Leopard; can't test newer versions).

IMN logo majestic logo threadwatch logo seochat tools logo