473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tkinter: unicode inconsistency on Windows

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

Jul 18 '05 #1
1 2758
Eric Brunel wrote:
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


Replying to myself: I gathered a few information from several sources and I
finally concluded that the problem lied in the file FixTk.py, as described in
http://minilien.com/?UThwyhrIGF

The reason for this problem is that the tcl/tk libraries get included before the
correct setup allowing them to find their available encodings was made.

So I replaced the file FixTk.py in <python install dir>/Lib/lib-tk by:

---FixTk.py--------------------
import sys, os
ver = '8.3' # You may have to replace this with your actual tcl/tk version
for t in "tcl", "tk":
v = os.path.join(sys.prefix, "tcl", t+ver)
if os.path.exists(os.path.join(v, "tclIndex")):
os.environ[t.upper() + "_LIBRARY"] = v
-------------------------------

This does not really solve the problem, since japanese characters still do not
show up in menu titles, even if a japanese font is installed. But it works with
the current Windows language: menu titles in french with a french version of
Windows are correctly displayed.
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas | last post by:
I was used to pass Unicode strings to Tk widgets. IIRC, Tcl/Tk expects UTF-8 encoded strings, but Tkinter took care of that. This worked, as long as I was using Python/Tk on Red Hat 9 Linux (and...
0
by: Michael Spencer | last post by:
Using: Python 2.3.3 Tkinter.TclVersion = 8.4000000000000004 Windows XP Calling edit_modified() on a Tkinter.Text object raises TypeError when it gets a Boolean True response. Exception in...
6
by: Batista, Facundo | last post by:
I tested the following simple code: ----------------- from Tkinter import * class App: def __init__(self, master): frame = Frame(master)
5
by: Ali | last post by:
I was wondering how one would go about displaying unicode in a Label object in a Tkinter window. I am trying to display text in another language. Please help.
7
by: Justin Ezequiel | last post by:
What font is Tkinter using for displaying utf-8 characters? On my Windows XP, most of the characters with names (unicodedata.name) are displayed WYSIWYG. However, on my Mandrake (warning: Linux...
1
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
7
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in...
4
by: dale cooper | last post by:
Hi everybody! I've recently installed python2.4.2 on Fedora 4 (from downloaded sources), but it appeared, that I can't use Tkinter module: >>> import Tkinter Traceback (most recent call last):...
7
by: krishnakant Mane | last post by:
hello all, I seam to have noticed this a bit late but it appears to me that tkinter is being used very widely for gui development on all platform? is that right? since fredric lundh has written a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.