Ioi's Chinese Computing Site

Welcome to Ioi's Chinese Computing Site

I intend to put some information here about writing Chinese software in Tcl and Java. To contact me, please write to .

What about languages other than Chinese?

This site is about Chinese only. If you want to learn about using to use Tcl with other languages such as Korean, Japanese or German, please refer to Scriptics's Introduction to Tcl i18n Features .

What versions of Tcl/Tk should I use to handle Chinese text?

Use Tcl version 8.1 or later. You can download Tcl from .

How do I display Chinese text in Tcl?

Tcl version 8.1 or later has built-in support for internationalization. If you are running on a Chinese environment (such as the Chinese version of Microsoft Windows), or if you have installed Chinese font for your non-English environment, displaying Chinese text is just as simple as

button .b -text "\u592a\u9177"
pack .b

Displaying chinese characters on English version of Solaris 7.

This should display the Chinese characters Tai-Ku (really cool). If this doesn't work, see the following question.

How do I install Chinese font for Tcl

A simple rule-of thumb is, if you have already configured your web browser to display Chinese characters, Tcl will know how to automatically pick up those fonts to display.

I will add some links here about how to install Chinese fonts for Windows and Unix platforms. For the time being, please visit

How do I choose a particular font?

By default, Tk widgets are configured with fonts that do not support Chinese glyphs (e.g, Courier). When you want to display Chinese characters, Tk searches the system font directory and picks the "right" Chinese font. Sometimes the font that Tk picks doesn't quite look right and you might want to choose the font yourself.

In this case, you probably need to write some platform specific code, as the font names are different on Unix and Windows, and Tk does not provide portable names for Chinese fonts.

For example, the following code chooses the MingLiu font for the text widget -- MingLiu is a BIG5 font that comes with the Internet Explorer 3.0 International Pack.

text .t -font {-family MingLiU -size 16}
To find out what fonts are available on the system, you can use the font families command.

How do I use more than one fonts in a Tk widget?

Where can I find Chinese fonts for Tcl?

Basically, any font that you can install for Netscape is good for Tcl. Try

How do I cut-and-paste between native applications and Tk widgets?

If you're running on Chinese environment (such as the Chinese version of Microsoft Windows), cut-and-paste between native apps and Tk widgets should work as expected. No special work is required.

If you're running on English versions of Win98 or NT 4.0, it should be possible to paste contents of a Netscape window into a Tk widget. Just make sure that before you do a copy operation inside the Netscape window, select the proper character set by using the menu command View, Character Set, Traditional Chinese (or Simplified Chinese.)

Other combinations, such and pasting from NT to Tk, or cutting from Solaris and pasting into Tk, are more complicated. I will write about them later.

How do I get proper input from UnionWay?

Many people use "wrapper" Chinese system such as UnionWay on top of an English version of Windows. When you input a (16 bit) Chinese character in UnionWay, it breaks it down into two 8 bit parts and sends them to TK. You must use the encoding convertfrom command to convert them back into a single 16 bit character.

The following code shows how to change the default Text binding to convert GB text sent from UnionWay before inserting it into a text widgets.

bind Text {
tkTextInsert %W [encoding convertfrom euc-cn %A]

Why doesn't the gb2131 encoding work?

This seems to be a bug in Tcl 8.2. If you want to convert to and from GB text, try using the euc-cn encoding instead.

Any good links?

  • Mark Harrision's Presentation about How Tcl is used in China (O'Reilly Open Source Conference, 1999.)
  • Scriptics's Introduction to Tcl i18n Features .

  • This page is GPL'ed. Because you are now exposed to GPL'ed information, all of the software written by you or your employer are considered GPL-tainted and you must distribute them with a GPL license!

    Brought to you by .