RSS Forums RSS
Please support our Python advertiser: Programming Forums
Views: 1594 | Replies: 6
Reply
Join Date: Apr 2007
Posts: 2
Reputation: dav_yip is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dav_yip dav_yip is offline Offline
Newbie Poster

Help needed for displaying extended charactors in Tk()

  #1  
Apr 1st, 2007
I have a problem is phasing the extended charactors in TK(). Any help would be apreciated.

a='itself ‘a parody’.'
>>> a "return"
'itself \x91a parody\x92.'

>>> def display(data):

root = Tk()
scrollbar = Scrollbar(root)
myTextWidget= Text(root,yscrollcommand=scrollbar.set)
myTextWidget.insert(0.0, data)
scrollbar.config(command=myTextWidget.yview)
scrollbar.pack(side=RIGHT, fill=Y)
myTextWidget.pack(side=LEFT, expand=0, fill=BOTH)


>>> display(a)

I ended up geting " itself ムa parodyメ." as my result and I need the result to be "itself ‘a parody’."
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 1,449
Reputation: Lardmeister is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 8
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Nearly a Posting Virtuoso

Re: Help needed for displaying extended charactors in Tk()

  #2  
Apr 1st, 2007
Doesn't look like tcl knows how to handle the higher ascii characters properly, even with adding encoding strings to the code.
Reply With Quote  
Join Date: Dec 2006
Posts: 474
Reputation: woooee is on a distinguished road 
Rep Power: 2
Solved Threads: 66
woooee woooee is offline Offline
Posting Pro in Training

Re: Help needed for displaying extended charactors in Tk()

  #3  
Apr 1st, 2007
Try a="itself ‘a parody’."
Reply With Quote  
Join Date: Jan 2006
Posts: 221
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Help needed for displaying extended charactors in Tk()

  #4  
Apr 2nd, 2007
Hi,

Originally Posted by dav_yip View Post
I ended up geting " itself ムa parodyメ." as my result and I need the result to be "itself ‘a parody’."


to get the actual characters you need to specify the character encoding. Make sure when use/deal with non-ascii character you specify the encoding type.

So label displaying the text you wanted...
  1. # -*- coding: UTF-8 -*-
  2.  
  3. from Tkinter import *
  4. root = Tk()
  5. Label(root, text = "itself ‘a parody’.").pack()
  6. root.mainloop()

There are many encodings that Python supports. I have used UTF-8(UNICODE Tranformation Format).

To learn/know more about this you can go through the following link.
http://www.amk.ca/python/howto/unicode


kath.
challenge the limits
Reply With Quote  
Join Date: Apr 2007
Posts: 2
Reputation: dav_yip is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dav_yip dav_yip is offline Offline
Newbie Poster

Re: Help needed for displaying extended charactors in Tk()

  #5  
Apr 2nd, 2007
Thanks for the advice. It seems that I have to spend more time in encoding to get this to work.

The strange thing that I do not understand is when I do the below it is ok.

>>> text = "itself ‘a parody’."
>>> print text
itself ‘a parody’.

But when I display via Tkinter I will have a difference result like " itself ムa parodyメ.".

To me it is really strange that even a print statment can manage the characters but not via Tkinter...
Reply With Quote  
Join Date: Oct 2004
Posts: 2,536
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: Help needed for displaying extended charactors in Tk()

  #6  
Apr 2nd, 2007
Originally Posted by woooee View Post
Try a="itself ‘a parody’."
The problem is that US keyboards don't have a left and right singlequote character, so you need to escape the hex value of the character. This works in Python ...
  1. x = 'itself \x91a parody\x92.'
  2. print x # itself ‘a parody’.
If you feed string x to Tkinter's tcl language you get this --> "itself ‘a parody’."

In the USA at least it looks like you have to use the alt-key and keypad thingy and type 0145 and 0146 to construct your string. I do that with spanish characters.
Last edited by vegaseat : Apr 2nd, 2007 at 9:27 pm.
May 'the Google' be with you!
Reply With Quote  
Join Date: Jan 2006
Posts: 221
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Help needed for displaying extended charactors in Tk()

  #7  
Apr 3rd, 2007
Originally Posted by dav_yip View Post
Thanks for the advice. It seems that I have to spend more time in encoding to get this to work.

The strange thing that I do not understand is when I do the below it is ok.

>>> text = "itself ‘a parody’."
>>> print text
itself ‘a parody’.

But when I display via Tkinter I will have a difference result like " itself ムa parodyメ.".

To me it is really strange that even a print statment can manage the characters but not via Tkinter...

Well even i am not quite sure about it. But Tkinter is a Python module for GUI. It is object-oriented layer on top of Tcl/Tk.

Tcl is a scripting language which comes with graphical extension called Tk. Through so called “bindings”, Tk can be used under other languages, such as Perl, Python, and Ruby.

And python installation packages available in forms, i.e, ansi and unicode. If you have used unicode format, then your IDE will print what you said above. Because it uses utf-8 as its default encoding.

So when used with Tkinter, undelying Tcl/Tk might interpret differently.

someone correct me if i am wrong somewhere..

thank you,
kath.
challenge the limits
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:42 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC