[Tutor] Floating point error in tkinter

Steven D'Aprano steve at pearwood.info
Fri Mar 9 15:40:06 CET 2012

On Fri, Mar 09, 2012 at 02:09:23PM +0100, Válas Péter wrote:
> Hi,
> I use a tkinter-based editor that ran properly earlier on English Windows
> XP. Now I use Hungarian Windows 7 with Python 2.7.2. You must know that in
> Hungary decimal fractions are marked with a decimal comma, not a dot (e.g.
> pi=3,1415...).
> I suspect it somehow gets a Hungarian decimal from Windows and can't
> understand it. So when I page up and down with PgUp/PgDn buttons, it works
> well. When I use the wheel on mouse, it's OK, too. But when I try to use
> the vertical scrollbar of the window with mouse, error messages flood my
> screen and it won't work. Dou you think this is a Python bug? 

What makes you think it is a Python bug? Is there something that makes 
you expect that Tkinter should accept strings with commas instead of 

The error message is pretty clear: tkinter is expecting a float, but 
receiving a string instead.

TclError: expected floating-point number but got "0,0016"

Unless there is documentation that says that it will accept strings 
with commas, this is not a Python bug. It may be a bug in the editor, 
but not in the Python language.

By the way, it seems that a lot of other code has this same problem.
You might find that running this:

import locale
locale.setlocale(locale.LC_ALL, 'english_us')

just before the editor starts up might help:



More information about the Tutor mailing list