Skip to content

Commit 1590d78

Browse files
gh-159301: Add missing symbolic constants to tkinter.constants (GH-159302)
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 8cef15c commit 1590d78

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
@@ -6845,6 +6845,17 @@ and :mod:`!tkinter.constants` namespaces.
68456845
edges) plus ``CENTER`` (``'center'``), used as values for the *anchor* and
68466846
*sticky* options and by methods such as :meth:`Misc.grid_anchor`.
68476847

6848+
.. data:: EN
6849+
ES
6850+
WN
6851+
WS
6852+
6853+
Additional values for the *labelanchor* option of :class:`LabelFrame`
6854+
and :class:`ttk.LabelFrame <tkinter.ttk.LabelFrame>`,
6855+
which also accept the compass directions above.
6856+
6857+
.. versionadded:: next
6858+
68486859
.. data:: LEFT
68496860
RIGHT
68506861
TOP
@@ -6881,6 +6892,13 @@ and :mod:`!tkinter.constants` namespaces.
68816892
Values for the *wrap* option of the :class:`Text` widget, selecting line
68826893
wrapping on character or word boundaries.
68836894

6895+
.. data:: TABULAR
6896+
WORDPROCESSOR
6897+
6898+
Values for the *tabstyle* option of the :class:`Text` widget.
6899+
6900+
.. versionadded:: next
6901+
68846902
.. data:: BASELINE
68856903

68866904
The text-alignment value ``'baseline'``.
@@ -6891,6 +6909,12 @@ and :mod:`!tkinter.constants` namespaces.
68916909
Values for the *bordermode* option of the placer (see
68926910
:meth:`Place.place_configure`).
68936911

6912+
.. data:: IGNORE
6913+
6914+
An additional value for the *bordermode* option of the placer.
6915+
6916+
.. versionadded:: next
6917+
68946918
.. data:: INSERT
68956919
CURRENT
68966920
END
@@ -6916,6 +6940,38 @@ and :mod:`!tkinter.constants` namespaces.
69166940

69176941
Values for the *state* option of various widgets and items.
69186942

6943+
.. data:: READONLY
6944+
6945+
An additional value for the *state* option of :class:`Entry`,
6946+
:class:`Spinbox` and the themed widgets.
6947+
6948+
.. versionadded:: next
6949+
6950+
.. data:: ALTERNATE
6951+
BACKGROUND
6952+
FOCUS
6953+
HOVER
6954+
INVALID
6955+
PRESSED
6956+
SELECTED
6957+
6958+
Names of the themed widget states
6959+
(see :meth:`ttk.Widget.state <tkinter.ttk.Widget.state>`),
6960+
in addition to ``ACTIVE``, ``DISABLED`` and ``READONLY``.
6961+
6962+
.. versionadded:: next
6963+
6964+
.. data:: LEAF
6965+
OPEN
6966+
6967+
Names of the themed widget states used by
6968+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`,
6969+
as are ``FIRST`` and ``LAST`` for the tabs of
6970+
:class:`ttk.Notebook <tkinter.ttk.Notebook>`.
6971+
They require Tk 9.1 or newer.
6972+
6973+
.. versionadded:: next
6974+
69196975
.. data:: CASCADE
69206976
CHECKBUTTON
69216977
COMMAND
@@ -6925,13 +6981,38 @@ and :mod:`!tkinter.constants` namespaces.
69256981
Menu entry types, used as the *itemType* argument of :meth:`Menu.add` and
69266982
:meth:`Menu.insert`.
69276983

6984+
.. data:: MENUBAR
6985+
TEAROFF
6986+
6987+
Values for the *type* option of the :class:`Menu` widget,
6988+
in addition to ``NORMAL``.
6989+
6990+
.. versionadded:: next
6991+
69286992
.. data:: SINGLE
69296993
BROWSE
69306994
MULTIPLE
69316995
EXTENDED
69326996

69336997
Values for the *selectmode* option of the :class:`Listbox` widget.
69346998

6999+
.. data:: ITEM
7000+
CELL
7001+
7002+
Values for the *selecttype* option of
7003+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`.
7004+
It requires Tk 9.0 or newer.
7005+
7006+
.. versionadded:: next
7007+
7008+
.. data:: TREE
7009+
HEADINGS
7010+
7011+
Values for the *show* option of
7012+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`.
7013+
7014+
.. versionadded:: next
7015+
69357016
.. data:: PIESLICE
69367017
CHORD
69377018
ARC
@@ -6966,6 +7047,74 @@ and :mod:`!tkinter.constants` namespaces.
69667047
Values for the *what* argument of :meth:`XView.xview_scroll` and
69677048
:meth:`YView.yview_scroll`.
69687049

7050+
.. data:: PIXELS
7051+
7052+
An additional value for the *what* argument of
7053+
:meth:`YView.yview_scroll` of the :class:`Text` widget.
7054+
7055+
.. versionadded:: next
7056+
7057+
.. data:: TEXT
7058+
IMAGE
7059+
7060+
Values for the *compound* option of the themed widgets,
7061+
in addition to ``CENTER``, ``LEFT``, ``RIGHT``, ``TOP``, ``BOTTOM``
7062+
and ``NONE``.
7063+
7064+
.. versionadded:: next
7065+
7066+
.. data:: ABOVE
7067+
BELOW
7068+
FLUSH
7069+
7070+
Values for the *direction* option of :class:`Menubutton` and
7071+
:class:`ttk.Menubutton <tkinter.ttk.Menubutton>`,
7072+
in addition to ``LEFT`` and ``RIGHT``.
7073+
7074+
.. versionadded:: next
7075+
7076+
.. data:: ALWAYS
7077+
MIDDLE
7078+
NEVER
7079+
7080+
Values for the *stretch* option of :meth:`PanedWindow.paneconfigure`,
7081+
in addition to ``FIRST`` and ``LAST``.
7082+
7083+
.. versionadded:: next
7084+
7085+
.. data:: DETERMINATE
7086+
INDETERMINATE
7087+
7088+
Values for the *mode* option of
7089+
:class:`ttk.Progressbar <tkinter.ttk.Progressbar>`.
7090+
7091+
.. versionadded:: next
7092+
7093+
.. data:: HOLLOW
7094+
7095+
An additional value for the *insertunfocussed* option of the
7096+
:class:`Text` widget, which also accepts ``NONE`` and ``SOLID``.
7097+
The option requires Tk 8.6 or newer.
7098+
7099+
.. versionadded:: next
7100+
7101+
.. data:: KEY
7102+
FOCUSIN
7103+
FOCUSOUT
7104+
7105+
Values for the *validate* option of :class:`Entry`, :class:`Spinbox`
7106+
and :class:`ttk.Entry <tkinter.ttk.Entry>`,
7107+
in addition to ``ALL``, ``FOCUS`` and ``NONE``.
7108+
7109+
.. versionadded:: next
7110+
7111+
.. data:: FORCED
7112+
7113+
An additional validation reason reported by the ``%V`` substitution
7114+
of the *validatecommand* option.
7115+
7116+
.. versionadded:: next
7117+
69697118
.. data:: UNDERLINE
69707119
NUMERIC
69717120
DOTBOX

‎Doc/whatsnew/3.16.rst‎

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

975+
* Added symbolic constants for Tk option values which were missing in
976+
:mod:`!tkinter.constants`: values for the *labelanchor*, *compound*,
977+
*bordermode*, *direction*, *stretch*, *tabstyle*, *insertunfocussed*,
978+
*mode*, *selecttype*, *show*, *state*, *validate* and *type* options,
979+
the names of the themed widget states, and ``PIXELS`` for scrolling
980+
the :class:`~tkinter.Text` widget.
981+
(Contributed by Serhiy Storchaka in :gh:`159301`.)
982+
975983

976984
turtle
977985
------

‎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)