Skip to content

Commit 5ed2f11

Browse files
bpo-13553: Document tkinter.Tk args (GH-4786)
(cherry picked from commit c56e2bb) Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
1 parent 826ceab commit 5ed2f11

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

Doc/library/tkinter.rst

+66-10
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,72 @@ the modern themed widget set and API::
124124
from tkinter import ttk
125125

126126

127-
.. class:: Tk(screenName=None, baseName=None, className='Tk', useTk=1)
128-
129-
The :class:`Tk` class is instantiated without arguments. This creates a toplevel
130-
widget of Tk which usually is the main window of an application. Each instance
131-
has its own associated Tcl interpreter.
132-
133-
.. FIXME: The following keyword arguments are currently recognized:
134-
135-
136-
.. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=0)
127+
.. class:: Tk(screenName=None, baseName=None, className='Tk', useTk=True, sync=False, use=None)
128+
129+
Construct a toplevel Tk widget, which is usually the main window of an
130+
application, and initialize a Tcl interpreter for this widget. Each
131+
instance has its own associated Tcl interpreter.
132+
133+
The :class:`Tk` class is typically instantiated using all default values.
134+
However, the following keyword arguments are currently recognized:
135+
136+
*screenName*
137+
When given (as a string), sets the :envvar:`DISPLAY` environment
138+
variable. (X11 only)
139+
*baseName*
140+
Name of the profile file. By default, *baseName* is derived from the
141+
program name (``sys.argv[0]``).
142+
*className*
143+
Name of the widget class. Used as a profile file and also as the name
144+
with which Tcl is invoked (*argv0* in *interp*).
145+
*useTk*
146+
If ``True``, initialize the Tk subsystem. The :func:`tkinter.Tcl() <Tcl>`
147+
function sets this to ``False``.
148+
*sync*
149+
If ``True``, execute all X server commands synchronously, so that errors
150+
are reported immediately. Can be used for debugging. (X11 only)
151+
*use*
152+
Specifies the *id* of the window in which to embed the application,
153+
instead of it being created as an independent toplevel window. *id* must
154+
be specified in the same way as the value for the -use option for
155+
toplevel widgets (that is, it has a form like that returned by
156+
:meth:`winfo_id`).
157+
158+
Note that on some platforms this will only work correctly if *id* refers
159+
to a Tk frame or toplevel that has its -container option enabled.
160+
161+
:class:`Tk` reads and interprets profile files, named
162+
:file:`.{className}.tcl` and :file:`.{baseName}.tcl`, into the Tcl
163+
interpreter and calls :func:`exec` on the contents of
164+
:file:`.{className}.py` and :file:`.{baseName}.py`. The path for the
165+
profile files is the :envvar:`HOME` environment variable or, if that
166+
isn't defined, then :attr:`os.curdir`.
167+
168+
.. attribute:: tk
169+
170+
The Tk application object created by instantiating :class:`Tk`. This
171+
provides access to the Tcl interpreter. Each widget that is attached
172+
the same instance of :class:`Tk` has the same value for its :attr:`tk`
173+
attribute.
174+
175+
.. attribute:: master
176+
177+
The widget object that contains this widget. For :class:`Tk`, the
178+
*master* is :const:`None` because it is the main window. The terms
179+
*master* and *parent* are similar and sometimes used interchangeably
180+
as argument names; however, calling :meth:`winfo_parent` returns a
181+
string of the widget name whereas :attr:`master` returns the object.
182+
*parent*/*child* reflects the tree-like relationship while
183+
*master*/*slave* reflects the container structure.
184+
185+
.. attribute:: children
186+
187+
The immediate descendants of this widget as a :class:`dict` with the
188+
child widget names as the keys and the child instance objects as the
189+
values.
190+
191+
192+
.. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=False)
137193

138194
The :func:`Tcl` function is a factory function which creates an object much like
139195
that created by the :class:`Tk` class, except that it does not initialize the Tk

Lib/tkinter/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ def wm_iconbitmap(self, bitmap=None, default=None):
20992099
the bitmap if None is given.
21002100
21012101
Under Windows, the DEFAULT parameter can be used to set the icon
2102-
for the widget and any descendents that don't have an icon set
2102+
for the widget and any descendants that don't have an icon set
21032103
explicitly. DEFAULT can be the relative path to a .ico file
21042104
(example: root.iconbitmap(default='myicon.ico') ). See Tk
21052105
documentation for more information."""
@@ -2345,9 +2345,9 @@ def destroy(self):
23452345
_default_root = None
23462346

23472347
def readprofile(self, baseName, className):
2348-
"""Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
2349-
the Tcl Interpreter and calls exec on the contents of BASENAME.py and
2350-
CLASSNAME.py if such a file exists in the home directory."""
2348+
"""Internal function. It reads .BASENAME.tcl and .CLASSNAME.tcl into
2349+
the Tcl Interpreter and calls exec on the contents of .BASENAME.py and
2350+
.CLASSNAME.py if such a file exists in the home directory."""
23512351
import os
23522352
if 'HOME' in os.environ: home = os.environ['HOME']
23532353
else: home = os.curdir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document tkinter.Tk args.

0 commit comments

Comments
 (0)