From 00fc1d72b2fa64139d3f496398c861085398c3f0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 13 Oct 2026 12:37:51 +0300 Subject: [PATCH] gh-159301: Add missing symbolic constants to tkinter.constants Add constants for the Tk option values which had none: values of the -labelanchor, -compound, -bordermode, -direction, -stretch, -tabstyle, -insertunfocussed, -mode, -selecttype, -show, -state, -validate and -type options, the names of the themed widget states, and PIXELS. --- Doc/library/tkinter.rst | 149 ++++++++++++++++++ Doc/whatsnew/3.16.rst | 8 + Lib/tkinter/constants.py | 68 ++++++++ ...-10-13-11-54-07.gh-issue-159301.Kq3Vx8.rst | 3 + 4 files changed, 228 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-13-11-54-07.gh-issue-159301.Kq3Vx8.rst diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index a6a30928ce83d21..86adcb51dfebb5a 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -6772,6 +6772,17 @@ and :mod:`!tkinter.constants` namespaces. edges) plus ``CENTER`` (``'center'``), used as values for the *anchor* and *sticky* options and by methods such as :meth:`Misc.grid_anchor`. +.. data:: EN + ES + WN + WS + + Additional values for the *labelanchor* option of :class:`LabelFrame` + and :class:`ttk.LabelFrame `, + which also accept the compass directions above. + + .. versionadded:: next + .. data:: LEFT RIGHT TOP @@ -6808,6 +6819,13 @@ and :mod:`!tkinter.constants` namespaces. Values for the *wrap* option of the :class:`Text` widget, selecting line wrapping on character or word boundaries. +.. data:: TABULAR + WORDPROCESSOR + + Values for the *tabstyle* option of the :class:`Text` widget. + + .. versionadded:: next + .. data:: BASELINE The text-alignment value ``'baseline'``. @@ -6818,6 +6836,12 @@ and :mod:`!tkinter.constants` namespaces. Values for the *bordermode* option of the placer (see :meth:`Place.place_configure`). +.. data:: IGNORE + + An additional value for the *bordermode* option of the placer. + + .. versionadded:: next + .. data:: INSERT CURRENT END @@ -6843,6 +6867,38 @@ and :mod:`!tkinter.constants` namespaces. Values for the *state* option of various widgets and items. +.. data:: READONLY + + An additional value for the *state* option of :class:`Entry`, + :class:`Spinbox` and the themed widgets. + + .. versionadded:: next + +.. data:: ALTERNATE + BACKGROUND + FOCUS + HOVER + INVALID + PRESSED + SELECTED + + Names of the themed widget states + (see :meth:`ttk.Widget.state `), + in addition to ``ACTIVE``, ``DISABLED`` and ``READONLY``. + + .. versionadded:: next + +.. data:: LEAF + OPEN + + Names of the themed widget states used by + :class:`ttk.Treeview `, + as are ``FIRST`` and ``LAST`` for the tabs of + :class:`ttk.Notebook `. + They require Tk 9.1 or newer. + + .. versionadded:: next + .. data:: CASCADE CHECKBUTTON COMMAND @@ -6852,6 +6908,14 @@ and :mod:`!tkinter.constants` namespaces. Menu entry types, used as the *itemType* argument of :meth:`Menu.add` and :meth:`Menu.insert`. +.. data:: MENUBAR + TEAROFF + + Values for the *type* option of the :class:`Menu` widget, + in addition to ``NORMAL``. + + .. versionadded:: next + .. data:: SINGLE BROWSE MULTIPLE @@ -6859,6 +6923,23 @@ and :mod:`!tkinter.constants` namespaces. Values for the *selectmode* option of the :class:`Listbox` widget. +.. data:: ITEM + CELL + + Values for the *selecttype* option of + :class:`ttk.Treeview `. + It requires Tk 9.0 or newer. + + .. versionadded:: next + +.. data:: TREE + HEADINGS + + Values for the *show* option of + :class:`ttk.Treeview `. + + .. versionadded:: next + .. data:: PIESLICE CHORD ARC @@ -6893,6 +6974,74 @@ and :mod:`!tkinter.constants` namespaces. Values for the *what* argument of :meth:`XView.xview_scroll` and :meth:`YView.yview_scroll`. +.. data:: PIXELS + + An additional value for the *what* argument of + :meth:`YView.yview_scroll` of the :class:`Text` widget. + + .. versionadded:: next + +.. data:: TEXT + IMAGE + + Values for the *compound* option of the themed widgets, + in addition to ``CENTER``, ``LEFT``, ``RIGHT``, ``TOP``, ``BOTTOM`` + and ``NONE``. + + .. versionadded:: next + +.. data:: ABOVE + BELOW + FLUSH + + Values for the *direction* option of :class:`Menubutton` and + :class:`ttk.Menubutton `, + in addition to ``LEFT`` and ``RIGHT``. + + .. versionadded:: next + +.. data:: ALWAYS + MIDDLE + NEVER + + Values for the *stretch* option of :meth:`PanedWindow.paneconfigure`, + in addition to ``FIRST`` and ``LAST``. + + .. versionadded:: next + +.. data:: DETERMINATE + INDETERMINATE + + Values for the *mode* option of + :class:`ttk.Progressbar `. + + .. versionadded:: next + +.. data:: HOLLOW + + An additional value for the *insertunfocussed* option of the + :class:`Text` widget, which also accepts ``NONE`` and ``SOLID``. + The option requires Tk 8.6 or newer. + + .. versionadded:: next + +.. data:: KEY + FOCUSIN + FOCUSOUT + + Values for the *validate* option of :class:`Entry`, :class:`Spinbox` + and :class:`ttk.Entry `, + in addition to ``ALL``, ``FOCUS`` and ``NONE``. + + .. versionadded:: next + +.. data:: FORCED + + An additional validation reason reported by the ``%V`` substitution + of the *validatecommand* option. + + .. versionadded:: next + .. data:: UNDERLINE NUMERIC DOTBOX diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 94693500116f48f..8c90289fd1058c3 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -765,6 +765,14 @@ tkinter with no unit suffix to :class:`int` or :class:`float`. (Contributed by Serhiy Storchaka in :gh:`153513`.) +* Added symbolic constants for Tk option values which were missing in + :mod:`!tkinter.constants`: values for the *labelanchor*, *compound*, + *bordermode*, *direction*, *stretch*, *tabstyle*, *insertunfocussed*, + *mode*, *selecttype*, *show*, *state*, *validate* and *type* options, + the names of the themed widget states, and ``PIXELS`` for scrolling + the :class:`~tkinter.Text` widget. + (Contributed by Serhiy Storchaka in :gh:`159301`.) + turtle ------ diff --git a/Lib/tkinter/constants.py b/Lib/tkinter/constants.py index 63eee33d24d6c7e..dcc326673b51744 100644 --- a/Lib/tkinter/constants.py +++ b/Lib/tkinter/constants.py @@ -18,6 +18,16 @@ NSEW='nsew' CENTER='center' +# -labelanchor, in addition to the values above +EN='en' +ES='es' +WN='wn' +WS='ws' + +# -compound +TEXT='text' +IMAGE='image' + # -fill NONE='none' X='x' @@ -54,8 +64,38 @@ # -bordermode INSIDE='inside' +IGNORE='ignore' OUTSIDE='outside' +# -direction +ABOVE='above' +BELOW='below' +FLUSH='flush' + +# -stretch +ALWAYS='always' +MIDDLE='middle' +NEVER='never' + +# -tabstyle +TABULAR='tabular' +WORDPROCESSOR='wordprocessor' + +# -insertunfocussed (Tk 8.6+) +HOLLOW='hollow' + +# -mode +DETERMINATE='determinate' +INDETERMINATE='indeterminate' + +# -selecttype (Tk 9.0+) +ITEM='item' +CELL='cell' + +# -show +TREE='tree' +HEADINGS='headings' + # Special tags, marks and insert positions SEL='sel' SEL_FIRST='sel.first' @@ -72,6 +112,29 @@ ACTIVE='active' # Canvas state HIDDEN='hidden' +# Entry and ttk widget states +READONLY='readonly' +# Other ttk widget states +ALTERNATE='alternate' +BACKGROUND='background' +FOCUS='focus' +HOVER='hover' +INVALID='invalid' +PRESSED='pressed' +SELECTED='selected' +# ttk widget states for Treeview items and Notebook tabs (Tk 9.1+) +# FIRST='first' and LAST='last' are also used +LEAF='leaf' +OPEN='open' + +# -validate +# ALL='all', FOCUS='focus' and NONE='none' are also valid +KEY='key' +FOCUSIN='focusin' +FOCUSOUT='focusout' + +# Validation reasons, in addition to the values above +FORCED='forced' # Menu item types CASCADE='cascade' @@ -80,6 +143,10 @@ RADIOBUTTON='radiobutton' SEPARATOR='separator' +# -type for menus +MENUBAR='menubar' +TEAROFF='tearoff' + # Selection modes for list boxes SINGLE='single' BROWSE='browse' @@ -108,3 +175,4 @@ SCROLL='scroll' UNITS='units' PAGES='pages' +PIXELS='pixels' diff --git a/Misc/NEWS.d/next/Library/2026-10-13-11-54-07.gh-issue-159301.Kq3Vx8.rst b/Misc/NEWS.d/next/Library/2026-10-13-11-54-07.gh-issue-159301.Kq3Vx8.rst new file mode 100644 index 000000000000000..067d1d5eac553cf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-13-11-54-07.gh-issue-159301.Kq3Vx8.rst @@ -0,0 +1,3 @@ +Add symbolic constants for Tk option values which were missing in +:mod:`!tkinter.constants`, such as ``READONLY``, ``TABULAR``, +``DETERMINATE``, ``MENUBAR`` and the names of the themed widget states.