This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unicode problem in Tkinter under Windows
Type: Stage:
Components: Tkinter Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: effbot Nosy List: effbot, lemburg, loewis, nobody
Priority: normal Keywords:

Created on 2001-04-23 09:41 by anonymous, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (4)
msg4489 - (view) Author: Nobody/Anonymous (nobody) Date: 2001-04-23 09:41
Unicode problem in Tkinter under Windows 2000
Keyboard-entered chars in ascii range > 128 mess up 
internal unicode encoding in text-widget leading to 
unicode errors

The following example should reproduce the bug:

>>> import Tkinter
>>> t=Tkinter.Text()
>>> t.pack()
>>> t.insert("1.0",u'\xe2\xee\xfb')

Now set the focus to the text-widget and via the 
keyboard enter an a umlaut into the text-widget 
(alternatively press ALT and enter 0228 on the Numpad 
of your Keyboard to simulate this)
Then test the result:
>>> t.get("1.0","end")
u'\xe2\xee\xfb\xe4\n'
This is what you get under Linux (I was told) and what 
it should be.
However, under Windows 2000 I get:
'\xc3\xa2\xc3\xae\xc3\xbb\xe4\n'
which is a mixture of UTF-8 and cp1252(?) leading to 
an Unicode-error, if I try e.g. to save it as a file.
(All characters of an 8-bit value > 128 (e.g. latin-1 
or cp1252) entered via keyboard into a text-widget 
cause such a weird behaviour, not just the a umlaut.)

A simple workaround (not thoroughly tested) could look 
like this:

def badkey(self, event):
    try:
        if ord(event.char) > 127:
            txt.insert("insert", unicode
(event.char,"cp1252"))
            return "break"
    except:
        pass

`txt` being the instance of a text-widget, that is 
bound to a callback for the key-press-event:

if sys.platform == "win32":
         txt.bind("<KeyPress>",badkey)
msg4490 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2001-04-23 11:29
Logged In: YES 
user_id=38388

I believe that this is a TCL bug. Could someone with more
Tcl/tk knowledge please review this ? If it is Unicode
related, then you can assign it back to me.

Thanks.
msg4491 - (view) Author: Nobody/Anonymous (nobody) Date: 2001-10-25 00:10
Logged In: NO 

This is a directory organization bug of Python.
Try and move "tcl8.3\" from "\Python2?\tcl\" to
"\Python2?\Lib\".

For details, see Request ID 474505 "Tkinter and its 
encodings on Windows" on the patch list.  It is a
rather well-known tip among Japanese pythoneers. 
msg4492 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-02-24 16:52
Logged In: YES 
user_id=21627

This is fixed with FixTk.py 1.6.
History
Date User Action Args
2022-04-10 16:03:59adminsetgithub: 34398
2001-04-23 09:41:05anonymouscreate