iso_8859_1 mystery/tkinter

P

phil

These work fine on Linux
s.const = {}
s.const['DEG'] = '%c' % (0xb0)
s.const['DIV'] = '%c' % (0xf7)
s.const['ANG'] = '%c' % (0xd8)

On WinXP the symbols for division and angle work fine.
But the symbol for degrees, a little circle, produces
a vertical bar in Tkinter Text box or Canvas.

However, if I run from IDLE and output to a console
window, 0xb0 produces the correct character for degrees.
Any idea why?
Thanks
 
?

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

phil said:
These work fine on Linux
s.const = {}
s.const['DEG'] = '%c' % (0xb0)
s.const['DIV'] = '%c' % (0xf7)
s.const['ANG'] = '%c' % (0xd8)

On WinXP the symbols for division and angle work fine.
But the symbol for degrees, a little circle, produces
a vertical bar in Tkinter Text box or Canvas.

I don't understand what you mean by that. Do you have
the symbol for degrees in your source code (so that
the editor for the source code displays it as a little
circle)? Or do you use the numeric code?

Can you show a small program that demonstrates this
effect?

Regards,
Martin
 
?

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

phil said:
These work fine on Linux
s.const = {}
s.const['DEG'] = '%c' % (0xb0)
s.const['DIV'] = '%c' % (0xf7)
s.const['ANG'] = '%c' % (0xd8)

On WinXP the symbols for division and angle work fine.
But the symbol for degrees, a little circle, produces
a vertical bar in Tkinter Text box or Canvas.

I don't understand what you mean by that. Do you have
the symbol for degrees in your source code (so that
the editor for the source code displays it as a little
circle)? Or do you use the numeric code?

Can you show a small program that demonstrates this
effect?

Regards,
Martin
 
V

vincent wehren

| phil wrote:
| > These work fine on Linux
| > s.const = {}
| > s.const['DEG'] = '%c' % (0xb0)
| > s.const['DIV'] = '%c' % (0xf7)
| > s.const['ANG'] = '%c' % (0xd8)
| >
| > On WinXP the symbols for division and angle work fine.
| > But the symbol for degrees, a little circle, produces
| > a vertical bar in Tkinter Text box or Canvas.
|
| I don't understand what you mean by that. Do you have
| the symbol for degrees in your source code (so that
| the editor for the source code displays it as a little
| circle)? Or do you use the numeric code?
|
| Can you show a small program that demonstrates this
| effect?

OP probably means something like:

import Tkinter
root = Tkinter.Tk()
t = Tkinter.Text()
t.pack()
t.insert(0.0, '%c' % 0xb0)
root.mainloop()

which shows a vertical bar in the Text widget.

Changing:

t.insert(0.0, '%c' % 0xb0)

to

t.insert(0.0, u'%c' % 0xb0)


should do the trick though.

--

Regards,

Vincent Wehren

|
| Regards,
| Martin
|
 
P

phil

| > s.const['DEG'] = '%c' % (0xb0)
| > But the symbol for degrees, a little circle, produces
| > a vertical bar in Tkinter Text box or Canvas.

t.insert(0.0, u'%c' % 0xb0)

should do the trick though.

COOL! Thanks, though that seems a little odd.
As far as I know %c ignores the sign bit everywhere
else, including X11 and Win consoles.
But I'll just note it and do it.
Thanks again.
 
J

Jeff Epler

this isn't about the "sign bit", it's about assumed encodings for byte
strings..

In iso_8859_1 and unicode, the character with value 0xb0 is DEGREE SIGN.
In other character sets, that may not be true---For instance, in the
Windows "code page 437", it is u'\u2591' aka LIGHT SHADE (a half-tone pattern).

When you write code like
x = '%c' % (0xb0)
and then pass x to a Tkinter call, Tkinter treats it as a string encoded
in some system-default encoding, which could give DEGREE SIGN, could
give LIGHT SHADE, or could give other characters (a thai user of Windows
might see THAI CHARACTER THO THAN, for instance, and I would see a
question mark because I use utf-8 and this is an invalid byte sequence).

By using
x = u'%c' % (0xb0)
you get a unicode string, and there is no confusion about the meaning of
the symbol---you always get DEGREE SIGN.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCi8loJd01MZaTXX0RAtIfAKCt6mj2SnJatJR2vfhAdvBBDgdFigCgqp6V
5MSwx4LSuM1jXR1iI57tgmY=
=fW7J
-----END PGP SIGNATURE-----
 
P

phil

Thanks.
My confusion was man 3 printf u is unsigned.
But of course that would be after %.
Never paid any attention to unicode,
but will now.


I'll figure out on my own why Tkinter and
WinXP console treated differently or used different
codepage. Thanks.
 

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
474,239
Messages
2,571,200
Members
47,840
Latest member
Tiffany471

Latest Threads

Top