Skip to content

Commit 00fc1d7

Browse files
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.
1 parent c04ad8c commit 00fc1d7

4 files changed

Lines changed: 228 additions & 0 deletions

File tree

‎Doc/library/tkinter.rst‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6772,6 +6772,17 @@ and :mod:`!tkinter.constants` namespaces.
67726772
edges) plus ``CENTER`` (``'center'``), used as values for the *anchor* and
67736773
*sticky* options and by methods such as :meth:`Misc.grid_anchor`.
67746774

6775+
.. data:: EN
6776+
ES
6777+
WN
6778+
WS
6779+
6780+
Additional values for the *labelanchor* option of :class:`LabelFrame`
6781+
and :class:`ttk.LabelFrame <tkinter.ttk.LabelFrame>`,
6782+
which also accept the compass directions above.
6783+
6784+
.. versionadded:: next
6785+
67756786
.. data:: LEFT
67766787
RIGHT
67776788
TOP
@@ -6808,6 +6819,13 @@ and :mod:`!tkinter.constants` namespaces.
68086819
Values for the *wrap* option of the :class:`Text` widget, selecting line
68096820
wrapping on character or word boundaries.
68106821

6822+
.. data:: TABULAR
6823+
WORDPROCESSOR
6824+
6825+
Values for the *tabstyle* option of the :class:`Text` widget.
6826+
6827+
.. versionadded:: next
6828+
68116829
.. data:: BASELINE
68126830

68136831
The text-alignment value ``'baseline'``.
@@ -6818,6 +6836,12 @@ and :mod:`!tkinter.constants` namespaces.
68186836
Values for the *bordermode* option of the placer (see
68196837
:meth:`Place.place_configure`).
68206838

6839+
.. data:: IGNORE
6840+
6841+
An additional value for the *bordermode* option of the placer.
6842+
6843+
.. versionadded:: next
6844+
68216845
.. data:: INSERT
68226846
CURRENT
68236847
END
@@ -6843,6 +6867,38 @@ and :mod:`!tkinter.constants` namespaces.
68436867

68446868
Values for the *state* option of various widgets and items.
68456869

6870+
.. data:: READONLY
6871+
6872+
An additional value for the *state* option of :class:`Entry`,
6873+
:class:`Spinbox` and the themed widgets.
6874+
6875+
.. versionadded:: next
6876+
6877+
.. data:: ALTERNATE
6878+
BACKGROUND
6879+
FOCUS
6880+
HOVER
6881+
INVALID
6882+
PRESSED
6883+
SELECTED
6884+
6885+
Names of the themed widget states
6886+
(see :meth:`ttk.Widget.state <tkinter.ttk.Widget.state>`),
6887+
in addition to ``ACTIVE``, ``DISABLED`` and ``READONLY``.
6888+
6889+
.. versionadded:: next
6890+
6891+
.. data:: LEAF
6892+
OPEN
6893+
6894+
Names of the themed widget states used by
6895+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`,
6896+
as are ``FIRST`` and ``LAST`` for the tabs of
6897+
:class:`ttk.Notebook <tkinter.ttk.Notebook>`.
6898+
They require Tk 9.1 or newer.
6899+
6900+
.. versionadded:: next
6901+
68466902
.. data:: CASCADE
68476903
CHECKBUTTON
68486904
COMMAND
@@ -6852,13 +6908,38 @@ and :mod:`!tkinter.constants` namespaces.
68526908
Menu entry types, used as the *itemType* argument of :meth:`Menu.add` and
68536909
:meth:`Menu.insert`.
68546910

6911+
.. data:: MENUBAR
6912+
TEAROFF
6913+
6914+
Values for the *type* option of the :class:`Menu` widget,
6915+
in addition to ``NORMAL``.
6916+
6917+
.. versionadded:: next
6918+
68556919
.. data:: SINGLE
68566920
BROWSE
68576921
MULTIPLE
68586922
EXTENDED
68596923

68606924
Values for the *selectmode* option of the :class:`Listbox` widget.
68616925

6926+
.. data:: ITEM
6927+
CELL
6928+
6929+
Values for the *selecttype* option of
6930+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`.
6931+
It requires Tk 9.0 or newer.
6932+
6933+
.. versionadded:: next
6934+
6935+
.. data:: TREE
6936+
HEADINGS
6937+
6938+
Values for the *show* option of
6939+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`.
6940+
6941+
.. versionadded:: next
6942+
68626943
.. data:: PIESLICE
68636944
CHORD
68646945
ARC
@@ -6893,6 +6974,74 @@ and :mod:`!tkinter.constants` namespaces.
68936974
Values for the *what* argument of :meth:`XView.xview_scroll` and
68946975
:meth:`YView.yview_scroll`.
68956976

6977+
.. data:: PIXELS
6978+
6979+
An additional value for the *what* argument of
6980+
:meth:`YView.yview_scroll` of the :class:`Text` widget.
6981+
6982+
.. versionadded:: next
6983+
6984+
.. data:: TEXT
6985+
IMAGE
6986+
6987+
Values for the *compound* option of the themed widgets,
6988+
in addition to ``CENTER``, ``LEFT``, ``RIGHT``, ``TOP``, ``BOTTOM``
6989+
and ``NONE``.
6990+
6991+
.. versionadded:: next
6992+
6993+
.. data:: ABOVE
6994+
BELOW
6995+
FLUSH
6996+
6997+
Values for the *direction* option of :class:`Menubutton` and
6998+
:class:`ttk.Menubutton <tkinter.ttk.Menubutton>`,
6999+
in addition to ``LEFT`` and ``RIGHT``.
7000+
7001+
.. versionadded:: next
7002+
7003+
.. data:: ALWAYS
7004+
MIDDLE
7005+
NEVER
7006+
7007+
Values for the *stretch* option of :meth:`PanedWindow.paneconfigure`,
7008+
in addition to ``FIRST`` and ``LAST``.
7009+
7010+
.. versionadded:: next
7011+
7012+
.. data:: DETERMINATE
7013+
INDETERMINATE
7014+
7015+
Values for the *mode* option of
7016+
:class:`ttk.Progressbar <tkinter.ttk.Progressbar>`.
7017+
7018+
.. versionadded:: next
7019+
7020+
.. data:: HOLLOW
7021+
7022+
An additional value for the *insertunfocussed* option of the
7023+
:class:`Text` widget, which also accepts ``NONE`` and ``SOLID``.
7024+
The option requires Tk 8.6 or newer.
7025+
7026+
.. versionadded:: next
7027+
7028+
.. data:: KEY
7029+
FOCUSIN
7030+
FOCUSOUT
7031+
7032+
Values for the *validate* option of :class:`Entry`, :class:`Spinbox`
7033+
and :class:`ttk.Entry <tkinter.ttk.Entry>`,
7034+
in addition to ``ALL``, ``FOCUS`` and ``NONE``.
7035+
7036+
.. versionadded:: next
7037+
7038+
.. data:: FORCED
7039+
7040+
An additional validation reason reported by the ``%V`` substitution
7041+
of the *validatecommand* option.
7042+
7043+
.. versionadded:: next
7044+
68967045
.. data:: UNDERLINE
68977046
NUMERIC
68987047
DOTBOX

‎Doc/whatsnew/3.16.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,14 @@ tkinter
765765
with no unit suffix to :class:`int` or :class:`float`.
766766
(Contributed by Serhiy Storchaka in :gh:`153513`.)
767767

768+
* Added symbolic constants for Tk option values which were missing in
769+
:mod:`!tkinter.constants`: values for the *labelanchor*, *compound*,
770+
*bordermode*, *direction*, *stretch*, *tabstyle*, *insertunfocussed*,
771+
*mode*, *selecttype*, *show*, *state*, *validate* and *type* options,
772+
the names of the themed widget states, and ``PIXELS`` for scrolling
773+
the :class:`~tkinter.Text` widget.
774+
(Contributed by Serhiy Storchaka in :gh:`159301`.)
775+
768776

769777
turtle
770778
------

‎Lib/tkinter/constants.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
NSEW='nsew'
1919
CENTER='center'
2020

21+
# -labelanchor, in addition to the values above
22+
EN='en'
23+
ES='es'
24+
WN='wn'
25+
WS='ws'
26+
27+
# -compound
28+
TEXT='text'
29+
IMAGE='image'
30+
2131
# -fill
2232
NONE='none'
2333
X='x'
@@ -54,8 +64,38 @@
5464

5565
# -bordermode
5666
INSIDE='inside'
67+
IGNORE='ignore'
5768
OUTSIDE='outside'
5869

70+
# -direction
71+
ABOVE='above'
72+
BELOW='below'
73+
FLUSH='flush'
74+
75+
# -stretch
76+
ALWAYS='always'
77+
MIDDLE='middle'
78+
NEVER='never'
79+
80+
# -tabstyle
81+
TABULAR='tabular'
82+
WORDPROCESSOR='wordprocessor'
83+
84+
# -insertunfocussed (Tk 8.6+)
85+
HOLLOW='hollow'
86+
87+
# -mode
88+
DETERMINATE='determinate'
89+
INDETERMINATE='indeterminate'
90+
91+
# -selecttype (Tk 9.0+)
92+
ITEM='item'
93+
CELL='cell'
94+
95+
# -show
96+
TREE='tree'
97+
HEADINGS='headings'
98+
5999
# Special tags, marks and insert positions
60100
SEL='sel'
61101
SEL_FIRST='sel.first'
@@ -72,6 +112,29 @@
72112
ACTIVE='active'
73113
# Canvas state
74114
HIDDEN='hidden'
115+
# Entry and ttk widget states
116+
READONLY='readonly'
117+
# Other ttk widget states
118+
ALTERNATE='alternate'
119+
BACKGROUND='background'
120+
FOCUS='focus'
121+
HOVER='hover'
122+
INVALID='invalid'
123+
PRESSED='pressed'
124+
SELECTED='selected'
125+
# ttk widget states for Treeview items and Notebook tabs (Tk 9.1+)
126+
# FIRST='first' and LAST='last' are also used
127+
LEAF='leaf'
128+
OPEN='open'
129+
130+
# -validate
131+
# ALL='all', FOCUS='focus' and NONE='none' are also valid
132+
KEY='key'
133+
FOCUSIN='focusin'
134+
FOCUSOUT='focusout'
135+
136+
# Validation reasons, in addition to the values above
137+
FORCED='forced'
75138

76139
# Menu item types
77140
CASCADE='cascade'
@@ -80,6 +143,10 @@
80143
RADIOBUTTON='radiobutton'
81144
SEPARATOR='separator'
82145

146+
# -type for menus
147+
MENUBAR='menubar'
148+
TEAROFF='tearoff'
149+
83150
# Selection modes for list boxes
84151
SINGLE='single'
85152
BROWSE='browse'
@@ -108,3 +175,4 @@
108175
SCROLL='scroll'
109176
UNITS='units'
110177
PAGES='pages'
178+
PIXELS='pixels'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add symbolic constants for Tk option values which were missing in
2+
:mod:`!tkinter.constants`, such as ``READONLY``, ``TABULAR``,
3+
``DETERMINATE``, ``MENUBAR`` and the names of the themed widget states.

0 commit comments

Comments
 (0)