473,657 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UNew to Tkinter nicodeEncodeErr or: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 unicodeEncodeEr ror when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeEr ror.

the snippet is given below

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

wordEntry = Entry(self.msgF rame,textvariab le=self.entStr)
#wordEntry.inse rt(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('sj is')
print "Inside search ...", word_utf.encode ('utf8')

I tried
word = '調べる' #some Japanese word in the quotes
word1 = word.decode('sj is')
print word1.encode('u tf8')

調べる #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 1182
ra************* ******@gmail.co m wrote:
It is working well when I enter english values.
But giving unicodeEncodeEr ror when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeEr ror.
chances are that Tkinter has already decoded the string for you.
def search(self):
word = self.entStr.get ()
word_utf = word.decode('sj is')
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('ut f8')

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('ut f8')
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.co m wrote:
It is working well when I enter english values.
But giving unicodeEncodeEr ror when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeEr ror.


chances are that Tkinter has already decoded the string for you.
def search(self):
word = self.entStr.get ()
word_utf = word.decode('sj is')
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('ut f8')

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('ut f8')
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.co m wrote:
It is working well when I enter english values.
But giving unicodeEncodeEr ror when I try with the Japanese letter.

I tried to decode it by but I am getting unicodeEncodeEr ror.


chances are that Tkinter has already decoded the string for you.
def search(self):
word = self.entStr.get ()
word_utf = word.decode('sj is')
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('ut f8')

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
1890
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 Tkinter import *
1
2804
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: ------------------------------- from Tkinter import * root = Tk() root.tk.call('encoding', 'system', 'utf-8')
4
2253
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 this? Cheers
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.