473,385 Members | 1,343 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,385 software developers and data experts.

UNew to Tkinter nicodeEncodeError:Japanese

Hi friends,

I am writing my Japanese study program and a GUIt.

I am facing a problem in an entry widget where I enter Japanese words.
The entered Japanese word is accessed by the callback function and used
for some processes.

It is working well when I enter english values.
But giving unicodeEncodeError when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeError.

the snippet is given below

class showex:
....
.......
def make gui
.....
....
self.entStr = StringVar()
self.entStr.set('Enter a Word Here')

wordEntry = Entry(self.msgFrame,textvariable=self.entStr)
#wordEntry.insert(0, 'Enter word Here')
wordEntry.pack(side=RIGHT)
wordEntry.focus()
wordEntry.bind('<Return>',self.search)

def previous(self):
if (self.inc > 9):
self.inc = self.inc -5
print 'Previous Executed', self.inc

def next(self):
self.inc = self.inc + 5
print 'Next Executed', self.inc

def search(self):
word = self.entStr.get()
word_utf = word.decode('sjis')
print "Inside search ...", word_utf.encode('utf8')

I tried
word = '調べる' #some Japanese word in the quotes
word1 = word.decode('sjis')
print word1.encode('utf8')

調べる #printed the Japanese word correctly

this is working nicely

What am I doing wrong here

I would greatly appreciate any help or suggestion.

Regards

raj

Dec 22 '05 #1
3 1173
ra*******************@gmail.com wrote:
It is working well when I enter english values.
But giving unicodeEncodeError when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeError.
chances are that Tkinter has already decoded the string for you.
def search(self):
word = self.entStr.get()
word_utf = word.decode('sjis')
print "Inside search ...", word_utf.encode('utf8')


try replacing this with

def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word.encode('utf8')

and let us know what it prints.

</F>

Dec 22 '05 #2
Thanks a lot for your reply Mr.Lundh

Yeah you are correct, Tkinter is automatically converting the words to
unicode, so there is no need to decode again, also there is no need to
encode in the print statement

so, your assumption is correct but the encode statement at print gave
me wrong kanjis [Japanese characters]
def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word.encode('utf8')
when I remove encode it is printing properly.

def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word

I referred unicode characters printed by repr to confirm. It is
perfect.

Thanks again (also for making you book available in the net)

-raj
Fredrik Lundh wrote: ra*******************@gmail.com wrote:
It is working well when I enter english values.
But giving unicodeEncodeError when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeError.


chances are that Tkinter has already decoded the string for you.
def search(self):
word = self.entStr.get()
word_utf = word.decode('sjis')
print "Inside search ...", word_utf.encode('utf8')


try replacing this with

def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word.encode('utf8')

and let us know what it prints.

</F>


Dec 22 '05 #3
Thanks a lot for your reply Mr.Lundh

Yeah you are correct, Tkinter is automatically converting the words to
unicode, so there is no need to decode again, also there is no need to
encode in the print statement

so, your assumption is correct but the encode statement at print gave
me wrong kanjis [Japanese characters]
def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word.encode('utf8')
when I remove encode it is printing properly.

def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word

I referred unicode characters printed by repr to confirm. It is
perfect.

Thanks again (also for making your book available in the net)

-raj
Fredrik Lundh wrote: ra*******************@gmail.com wrote:
It is working well when I enter english values.
But giving unicodeEncodeError when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeError.


chances are that Tkinter has already decoded the string for you.
def search(self):
word = self.entStr.get()
word_utf = word.decode('sjis')
print "Inside search ...", word_utf.encode('utf8')


try replacing this with

def search(self):
word = self.entStr.get()
print repr(word)
print "Inside search ...", word.encode('utf8')

and let us know what it prints.

</F>


Dec 22 '05 #4

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

Similar topics

1
by: Adolfo | last post by:
Hi: First Issue. I came home to review the GUI making code I wa given at my first Python workshop to find out that the TK of my Python installation is stuck somewhere. If I type: from...
1
by: Eric Brunel | last post by:
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: -------------------------------...
4
by: Sven Erik Knop | last post by:
Hi probably an old problem, but maybe you can help me: Just installed Python 2.3.4 on Windows XP SP1, and although the interpreter runs fine, IDLE will not start. Any ideas how to solve...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.