Japanese Input in Tcl/Tk
This page simply lists the tricks for getting Japanese input working into
a Tk widget. This is under Linux (tested with Redhat 7.1, & .2 and recent
SuSE versions.)
- you need Tcl/Tk 8.3.4 or later
- you need a Japanese IME such as
kinput2
running with the XIM protocol turned on. My command for doing this is:
-
kinput2 -canna -xim &
- you also need the usual things set for running kinput2, e.g.
XMODIFIERS=@im=kinput2,
etc.
- before launching the script, (e.g.
wish myscript.tcl)
you need to set the LC_CTYPE environment variable to "ja_JP". Without
this, Tcl/Tk will not try and engage the right IME. You
may
also have to set LC_ALL to "ja_JP" too; I found this to be a bit
sensitive to OS version, etc.
(And these have to be set before starting the interpreter. It
can't be changed dynamically later.)
- in your Tcl/Tk code, you may need to enable the IME access via the XIM protocol, e.g.
-
set imtest [tk useinputmethods 1]
(In later versions of Tcl this is enabled by default. Printing out the value
of $imtest will confirm that the XIM protocol is enabled.)
- once the script is running you can invoke kinput2 for a tk text box
in the usual way, e.g. Shift-Space.
(Note that in 8.3.4 this brings up the old "root window" style of kinput2
operation. The modern "over-the-spot" style is there in
8.4b1+.)
Jim Breen
May 2004
Jim Breen's Home Page and Japanese Page.