By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

Tkinter and utf-8

P: n/a
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 newbie), most characters are
displayed as \u???? where ???? is the Hex code.

## start of script Tkinter_gui.py----------
import Tkinter
import ScrolledText
import codecs
import tkFont

##FONT = 'Courier'

class MyFrame(Tkinter.Frame):
def __init__(self, master=None):
self.root = master
Tkinter.Frame.__init__(self, master)
self.pack(fill=Tkinter.BOTH, expand=1)
## self.textBox = ScrolledText.ScrolledText(self, font=(FONT, 12))
self.textBox = ScrolledText.ScrolledText(self,
font=tkFont.Font(size=12))
self.textBox.pack(fill=Tkinter.BOTH, expand=1)

def write(self, txt):
self.textBox.insert(Tkinter.END, txt)
self.textBox.see(Tkinter.END)
self.textBox.update_idletasks()

if __name__ == '__main__':
root = Tkinter.Tk()

frame = MyFrame(root)

f = codecs.open('named.txt', 'r', 'utf-8')
frame.write('\n'.join(f.read().splitlines()))
f.close()

root.minsize(640, 480)
Tkinter.mainloop()
## end of script ----------

Python 2.3.3 (#2, Feb 17 2004, 11:45:40)
[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2

and

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
MS Windows XP SP2

Please CC me directly as I am not subscribed

BTW, tried to e-mail directly (with 2 jpeg screenshots and the named.txt file)
but got the following:

This is an automatically generated Delivery Status Notification

Delivery to the following recipient failed permanently:

py*********@python.org

Technical details of failure:
PERM_FAILURE: SMTP Error (state 13): 553 rejected, message looks like spam.
Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi !

In XP (and 2000), the display of unicode use the uniscribe motor. But the
standards win's versions are not (all) in top level. You MUST install more
recent version.

I had do this update, and, now, I can use really unicode in Windows (samples
: directory name in unicode, in windows explorer).
Sample code of tk display of unicode string :

root = Tk()
myFont = tkFont.Font(size=18)
w = Label(root, text=unicodstring, font=myFont)
w.pack()
root.mainloop()

Aaah ! Last "truc" : uniscribe is in USP10.DLL (look the version)


*sorry for my bad english*
@-salutations
--
Michel Claveau

Jul 18 '05 #2

P: n/a
Michel Claveau writes:
In XP (and 2000), the display of unicode use the uniscribe motor. But the
standards win's versions are not (all) in top level. You MUST install more
recent version.


Thank you.
Found a page on microsoft.com about Uniscribe and will be reading it
thoroughly.

Any tips for a Mandrake newbie for getting a few more characters displayed
WYSIWYG?
I am actually considering writing a replacement for SC UniPad which we use on
our Windows boxes.
Jul 18 '05 #3

P: n/a
Justin Ezequiel wrote:
Any tips for a Mandrake newbie for getting a few more characters displayed
WYSIWYG?


What characters specifically are you missing? In general, the answer is
"install more fonts". Tk is pretty smart in finding the right font,
provided an appropriate font is available. Do xlsfonts(1) to see whether
you have a good number of fonts installed. On my system, I get

martin@mira:~/work/py2.4/Lib$ xlsfonts|wc
8317 10959 495020

and I'm confident that Tk would display any character I could ever
encounter.

Regards,
Martin
Jul 18 '05 #4

P: n/a
Among others, I am missing characters in the range
017F 383 LATIN SMALL LETTER LONG S
to
036F 879 COMBINING LATIN SMALL LETTER X

my xlsfonts numbers:
448 539 24261

I'll get some help here re obtaining fonts.
Thank you.
Jul 18 '05 #5

P: n/a
Hi !
Mandrake newbie


What is Mandrake ? The magician ? A comic personn ?
I am not in love with Linux... ;o)
Michel Claveau


Jul 18 '05 #6

P: n/a
Justin Ezequiel <je*******@gmail.com> wrote:
Among others, I am missing characters in the range
017F 383 LATIN SMALL LETTER LONG S
to
036F 879 COMBINING LATIN SMALL LETTER X my xlsfonts numbers:
448 539 24261
The numbers don't help a lot, but you can use xlsfonts to get better
information. Unicode encoding is 'iso10646-1', so do

xlsfonts -fn '*iso10646*'

to see what unicode fonts you have in the first place. Adding -lll
will list metrics for each character, so do (for example)

xlsfonts -lll -fn '*iso10646*' | grep 0x17f

to see all the metrics for LATIN SMALL LETTER LONG S. If any of these
have non-zero metrics, the character is available. Inspect the full
output to find the complete font name, and use 'xfd' to display the
font. On my system, for example, all *misc* fonts have this character,
but the *helvetica* fonts don't.

Finally, you have to make sure Tk uses the fonts. IIRC Tkinter allows
you to access the Tk option database, so set the font options
with X-style names. That should do the trick, but I didn't check.
I'll get some help here re obtaining fonts.
Thank you.


I use Debian, not Mandrake, but you should be able to download Mandrake
packages for fonts somewhere, if necessary. Make sure there is no version
clash with the X server you are using.

- Dirk
Jul 18 '05 #7

P: n/a
Dirk Thierbach writes:
xlsfonts -lll -fn '*iso10646*' | grep 0x17f

to see all the metrics for LATIN SMALL LETTER LONG S. If any of these
have non-zero metrics, the character is available. Inspect the full
output to find the complete font name, and use 'xfd' to display the
font. On my system, for example, all *misc* fonts have this character,
but the *helvetica* fonts don't.
Thanks, I will try this.
Finally, you have to make sure Tk uses the fonts. IIRC Tkinter allows
you to access the Tk option database, so set the font options
with X-style names. That should do the trick, but I didn't check.


Will have to research how this is done.
Thanks again.

BTW, in the meantime, I've copied and installed 'Arial Unicode MS' from my
WinXP box.
Explicitly telling Tkinter to use that font seems to work just find here on my
Mandrake box but I am uneasy about the legality of this.
Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.