Skip to content

Commit ae7f7d7

Browse files
gh-84008: Document that the LC_NUMERIC locale affects tkinter numeric widgets
Spinbox, Scale and ttk.Spinbox format floating-point values according to the LC_NUMERIC locale, but such values are always parsed with a period, so a comma-decimal locale breaks DoubleVar.get(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2ac1611 commit ae7f7d7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,6 +5042,9 @@ Widget classes
50425042
dropped; *from* is spelled ``from_`` because :keyword:`from` is a Python
50435043
keyword.
50445044

5045+
With a non-integer *resolution*, see :ref:`numeric values and the locale
5046+
<tkinter-numeric-locale>`.
5047+
50455048
.. method:: get()
50465049

50475050
Return the current value of the scale.
@@ -5140,6 +5143,9 @@ Widget classes
51405143
text.
51415144
Inherits from :class:`Widget` and :class:`XView`.
51425145

5146+
With a non-integer *increment*, see :ref:`numeric values and the locale
5147+
<tkinter-numeric-locale>`.
5148+
51435149
Many of the methods take an *index* argument identifying a character in the
51445150
spinbox's string.
51455151
As described in the Tk ``spinbox`` manual page, *index* may be a numeric
@@ -6028,6 +6034,18 @@ Variable classes
60286034

60296035
Return the value of the variable as a :class:`float`.
60306036

6037+
.. _tkinter-numeric-locale:
6038+
6039+
.. note::
6040+
6041+
A floating-point value is always parsed with a period (``.``) as the
6042+
decimal separator, but :class:`Spinbox`, :class:`Scale` and
6043+
:class:`ttk.Spinbox <tkinter.ttk.Spinbox>` format it according to the
6044+
``LC_NUMERIC`` locale. Under a locale that uses a comma they produce a
6045+
value that :meth:`get` cannot read, raising :exc:`TclError`. Set
6046+
``LC_NUMERIC`` to a locale that uses a period (such as ``'C'``) to avoid
6047+
this.
6048+
60316049

60326050
.. class:: BooleanVar(master=None, value=None, name=None)
60336051

Doc/library/tkinter.ttk.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ ttk.Spinbox
463463

464464
.. class:: Spinbox
465465

466+
With a non-integer increment, see :ref:`numeric values and the locale
467+
<tkinter-numeric-locale>`.
468+
466469
.. versionadded:: 3.8
467470

468471
.. method:: get()

0 commit comments

Comments
 (0)