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
- you need Tcl/Tk 8.3.4 or later
- you need a Japanese IME such as
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.
- before launching the script, (e.g.
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
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.
(In later versions of Tcl this is enabled by default. Printing out the value
of $imtest will confirm that the XIM protocol is enabled.)
set imtest [tk useinputmethods 1]
- 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
Jim Breen's Home Page and Japanese Page.