Skip to content

Commit b7a8786

Browse files
bpo-13553: Document tkinter.Tk args (GH-4786)
(cherry picked from commit c56e2bb) Co-authored-by: Cheryl Sabella <[email protected]>
1 parent 1fb25a9 commit b7a8786

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

Doc/library/tkinter.rst

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,72 @@ the modern themed widget set and API::
6363
from tkinter import ttk
6464

6565

66-
.. class:: Tk(screenName=None, baseName=None, className='Tk', useTk=1)
67-
68-
The :class:`Tk` class is instantiated without arguments. This creates a toplevel
69-
widget of Tk which usually is the main window of an application. Each instance
70-
has its own associated Tcl interpreter.
71-
72-
.. FIXME: The following keyword arguments are currently recognized:
73-
74-
75-
.. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=0)
66+
.. class:: Tk(screenName=None, baseName=None, className='Tk', useTk=True, sync=False, use=None)
67+
68+
Construct a toplevel Tk widget, which is usually the main window of an
69+
application, and initialize a Tcl interpreter for this widget. Each
70+
instance has its own associated Tcl interpreter.
71+
72+
The :class:`Tk` class is typically instantiated using all default values.
73+
However, the following keyword arguments are currently recognized:
74+
75+
*screenName*
76+
When given (as a string), sets the :envvar:`DISPLAY` environment
77+
variable. (X11 only)
78+
*baseName*
79+
Name of the profile file. By default, *baseName* is derived from the
80+
program name (``sys.argv[0]``).
81+
*className*
82+
Name of the widget class. Used as a profile file and also as the name
83+
with which Tcl is invoked (*argv0* in *interp*).
84+
*useTk*
85+
If ``True``, initialize the Tk subsystem. The :func:`tkinter.Tcl() <Tcl>`
86+
function sets this to ``False``.
87+
*sync*
88+
If ``True``, execute all X server commands synchronously, so that errors
89+
are reported immediately. Can be used for debugging. (X11 only)
90+
*use*
91+
Specifies the *id* of the window in which to embed the application,
92+
instead of it being created as an independent toplevel window. *id* must
93+
be specified in the same way as the value for the -use option for
94+
toplevel widgets (that is, it has a form like that returned by
95+
:meth:`winfo_id`).
96+
97+
Note that on some platforms this will only work correctly if *id* refers
98+
to a Tk frame or toplevel that has its -container option enabled.
99+
100+
:class:`Tk` reads and interprets profile files, named
101+
:file:`.{className}.tcl` and :file:`.{baseName}.tcl`, into the Tcl
102+
interpreter and calls :func:`exec` on the contents of
103+
:file:`.{className}.py` and :file:`.{baseName}.py`. The path for the
104+
profile files is the :envvar:`HOME` environment variable or, if that
105+
isn't defined, then :attr:`os.curdir`.
106+
107+
.. attribute:: tk
108+
109+
The Tk application object created by instantiating :class:`Tk`. This
110+
provides access to the Tcl interpreter. Each widget that is attached
111+
the same instance of :class:`Tk` has the same value for its :attr:`tk`
112+
attribute.
113+
114+
.. attribute:: master
115+
116+
The widget object that contains this widget. For :class:`Tk`, the
117+
*master* is :const:`None` because it is the main window. The terms
118+
*master* and *parent* are similar and sometimes used interchangeably
119+
as argument names; however, calling :meth:`winfo_parent` returns a
120+
string of the widget name whereas :attr:`master` returns the object.
121+
*parent*/*child* reflects the tree-like relationship while
122+
*master*/*slave* reflects the container structure.
123+
124+
.. attribute:: children
125+
126+
The immediate descendants of this widget as a :class:`dict` with the
127+
child widget names as the keys and the child instance objects as the
128+
values.
129+
130+
131+
.. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=False)
76132

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

Lib/tkinter/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ def wm_iconbitmap(self, bitmap=None, default=None):
20702070
the bitmap if None is given.
20712071
20722072
Under Windows, the DEFAULT parameter can be used to set the icon
2073-
for the widget and any descendents that don't have an icon set
2073+
for the widget and any descendants that don't have an icon set
20742074
explicitly. DEFAULT can be the relative path to a .ico file
20752075
(example: root.iconbitmap(default='myicon.ico') ). See Tk
20762076
documentation for more information."""
@@ -2316,9 +2316,9 @@ def destroy(self):
23162316
_default_root = None
23172317

23182318
def readprofile(self, baseName, className):
2319-
"""Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
2320-
the Tcl Interpreter and calls exec on the contents of BASENAME.py and
2321-
CLASSNAME.py if such a file exists in the home directory."""
2319+
"""Internal function. It reads .BASENAME.tcl and .CLASSNAME.tcl into
2320+
the Tcl Interpreter and calls exec on the contents of .BASENAME.py and
2321+
.CLASSNAME.py if such a file exists in the home directory."""
23222322
import os
23232323
if 'HOME' in os.environ: home = os.environ['HOME']
23242324
else: home = os.curdir
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document tkinter.Tk args.

0 commit comments

Comments
 (0)