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

2020-03-04 Thread Till Korten


Till Korten  added the comment:

I just found the following code in lines 314-320 of 
[tkinter/ttk.py](https://github.com/python/cpython/blob/master/Lib/tkinter/ttk.py),
 which are clearly not localization-aware:
```
def _to_number(x):
if isinstance(x, str):
if '.' in x:
x = float(x)
else:
x = int(x)
return x
```

I'll keep looking for similar stuff and add a pull request once I think I have 
nailed down the issue
I'll look for something similar in

--

___
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



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

2020-03-02 Thread Till Korten


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