How to change codepage (encoding) in Tcl/Tk

Richard.Suchenwirth Richard.Suchenwirth at kst.siemens.de
Wed Jun 20 09:35:03 EDT 2001


Peteris Martinsons wrote:
> 
> I have a UI form, written in BeOpen Python 2.1 with Tcl/Tk that has 4
> text boxes.
> I want 2 of them to display text in English and 2 in Russian. Is this
> possible? If Yes, how do I do this? Which is the property to alter?

In Tcl/Tk, all strings are internally represented as Unicode/UTF-8. This
extends to text in Tk widgets as well - if you just have at least one
font that "implements" a certain Unicode, Tk widgets will happily
display it without any need for configuration.
So, to put some Russian into a text widget in Tcl, just say

.t insert end \u0413\u0414\u041F

Other encodings will however come into play when doing file I/O
(including stdin/out).
Want to read a Russian text file in koi-8 encoding?

set f [open $filename]
fconfigure $f -encoding koi8-r ;# this is important!
set text [read $f]
close $f

For a converter from 7-bit ASCII encoding to Russian Unicodes, see
"Ruslish",   http://mini.net/cgi-bin/wikit/712.html
-- 
Schoene Gruesse/best regards, Richard Suchenwirth - +49-7531-86 2703
Siemens Dematic AG, PA RC D2, Buecklestr.1-5, 78467 Konstanz,Germany
Personal opinions expressed only unless explicitly stated otherwise.



More information about the Python-list mailing list