Tkinter and utf-8

J

Justin Ezequiel

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:

(e-mail address removed)

Technical details of failure:
PERM_FAILURE: SMTP Error (state 13): 553 rejected, message looks like spam.
 
M

Michel Claveau - abstraction méta-galactique non t

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
 
J

Justin Ezequiel

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.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Justin said:
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
 
J

Justin Ezequiel

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.
 
D

Dirk Thierbach

Justin Ezequiel said:
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
 
M

Michel Claveau - abstraction méta-galactique non t

Hi !

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


Michel Claveau
 
J

Justin Ezequiel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top