New submission from Till Korten :
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
<https://bugs.python.org/issue39827>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com