[New-bugs-announce] [issue39827] setting a locale that uses comma as decimal separator breaks tkinter.DoubleVar

Till Korten report at bugs.python.org
Mon Mar 2 10:11:30 EST 2020


New submission from Till Korten <webmaster at korten.at>:

This issue occurs when a locale is set that uses comma as decimal separator (e.g. locale.setlocale(locale.LC_NUMERIC, 'de_DE.utf8')).
I have a tkinter.Spinbox with increment=0.1 connected to a tkinter.DoubleVar.
When I change the value of the Spinbox using the arrow buttons and subsequently try to read out the variable with tkinter.DoubleVar.get(), my code throws the follwoing error:
_tkinter.TclError: expected floating-point number but got "0,1".

Here is a minimal code example:

-------------
import tkinter
import locale

locale.setlocale(locale.LC_NUMERIC, 'de_DE.utf8')


class TestDoubleVar():
    def __init__(self):
        root = tkinter.Tk()
        self.var = tkinter.DoubleVar()
        self.var.set(0.8)
        number = tkinter.Spinbox(
            root,
            from_=0, to=1, increment=0.1,
            textvariable=self.var,
            command=self.update,
            width=4
        )
        number.pack(side=tkinter.LEFT)
        root.mainloop()

    def update(self, *args):
        print(float(self.var.get()))


if __name__ == '__main__':
    TestDoubleVar()

-------

Actual result: the code throws an error

Expected result: the code should print the values of the DoubleVar even with a locale set that uses comma as the decimal separator.

n.b. the problem also occurs with tkinter.Scale

----------
components: Tkinter
files: test_doublevar.py
messages: 363184
nosy: thawn
priority: normal
severity: normal
status: open
title: setting a locale that uses comma as decimal separator breaks tkinter.DoubleVar
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48943/test_doublevar.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39827>
_______________________________________


More information about the New-bugs-announce mailing list