How to get a unicode degrees symbol?
Martin von Loewis
loewis at informatik.hu-berlin.de
Thu Jun 7 05:42:59 EDT 2001
"Russell E. Owen" <owen at astrono.junkwashington.emu> writes:
> My main goal is to display the degree symbol (for example) on the
> current platform -- in a way that Tk, etc. can all handle it as a normal
> thing.
>
> Apparently this requires encoding the data as an ascii string.
No. First, an ASCII string (as in "American Standard Code for
Information Interchange") does not support the degree symbol.
You probably meant a "byte string encoded as Latin-1".
However, since Python 2.0 (and Tk 8.x), displaying Unicode objects in
Tk windows is the best option. You don't need to care at all what font
to chose and what encoding; Tk will do the right thing (most of the
time).
> OK, but surely there must be some simple way to do this that doesn't
> require a big case statement (if platform x then use encoding y...)
> and knowing the name of the most appropriate encoding for each
> platform?
Indeed there is, the code
>>> import Tkinter
>>> l=Tkinter.Label(text=u"\N{DEGREE SIGN}")
>>> l.pack()
should work on every system (provided a Tk port and proper fonts are
available).
Regards,
Martin
More information about the Python-list
mailing list