Tkinter: unicode inconsistency on Windows

Eric Brunel eric.brunel at N0SP4M.com
Tue Feb 24 07:15:18 EST 2004


Hi all,

I'm in the process of localizing a Tkinter application and I'm struggling with a 
problem for which I can't figure out a solution. The following code:

-------------------------------
from Tkinter import *

root = Tk()
root.tk.call('encoding', 'system', 'utf-8')
mb = Menu(root)
root.configure(menu=mb)
m = Menu(mb)
## s1 is UTF8 japanese for hi.ra.ga.na
s1 = '\xe3\x81\xb2\xe3\x82\x89\xe3\x81\x8c\xe3\x81\xaa'
mb.add_cascade(label=s1, menu=m)
## s2 is UTF8 japanese for KA.TA.KA.NA
s2 = '\xe3\x82\xab\xe3\x82\xbf\xe3\x82\xab\xe3\x83\x8a'
m.add_cascade(label=s2)

root.mainloop()
-------------------------------

works perfectly well on Unix (Linux Mandrake 8.0), but not on Windows 2k: the 
menu item is correctly displayed as japanese katakana characters, but the menu 
title is displayed incorrectly in a way that looks like a wrong encoding has 
been used. I tried to explicitely pass unicode strings to Tkinter methods 
(unicode(s?, 'utf-8')) and/or to force the system encoding at tcl/tk's level via 
root.tk.call('encoding', 'system', 'utf-8'), but nothing seems to help.

AFAICS, the menu bar accepts only titles encoded in latin1; any other encoding 
ends up messed up.

So I'm stuck: I can't find any way to display menu titles in anything else than 
latin1 under Windows. Here are the versions I use:
  - Python 2.1.1
  - tcl/tk 8.3.2
  - Windows 2k, french version if it changes anything

TIA
-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list