@@ -21,7 +21,7 @@ installed, so you can read the Tcl/Tk documentation specific to that version.
21
21
22
22
Tkinter supports a range of Tcl/Tk versions, built either with or
23
23
without thread support. The official Python binary release bundles Tcl/Tk 8.6
24
- threaded. See the source code for the underlying :mode: `_tkinter ` C module
24
+ threaded. See the source code for the :mode: `_tkinter ` module
25
25
for more information about supported versions.
26
26
27
27
Tkinter is not a thin wrapper, it adds a fair amount of own logic to
@@ -35,7 +35,7 @@ Architecture
35
35
36
36
Unlike most other GUI toolkits, Tcl/Tk is not a monolithic product providing a
37
37
consolidated API. Instead, it's a bundle of libraries, each with its
38
- separate functionality and documentation.
38
+ distinct functionality and separate documentation.
39
39
40
40
Tcl
41
41
Tcl is a dynamic interpreted programming language. Though it can be used
44
44
an interface to the Tk toolkit. The Tcl engine library has a C interface to
45
45
create and operate interpreter instances, run Tcl commands and scripts with
46
46
them and add custom commands that can be implemented in either Tcl or C.
47
- It also implements a per-interpreter event queue. Each :class: `Tk ` object
48
- embeds its own interpreter instance. Though :mod: `_tkinter ` allows to
49
- execute entire Tcl scripts, the Python bindings typically only run single
50
- commands.
47
+ It also implements a per-thread event queue (see `Threading model `_ for
48
+ details).
49
+ Each :class: `Tk ` object embeds its own interpreter instance.
50
+ Though :mod: `_tkinter ` allows to execute entire Tcl scripts, the Python
51
+ bindings typically only run single commands.
51
52
52
53
Tk
53
54
Tk is a Tcl module implemented in C that adds custom commands to create and
62
63
`tkinter ` mostly uses the latter.
63
64
64
65
Tix
65
- `Tix`<https://core.tcl.tk/jenglish/gutter/packages/tix.html> is a
66
+ `Tix`<https://core.tcl.tk/jenglish/gutter/packages/tix.html>_ is a
66
67
third-party Tcl module, an addon for Tk that adds several new widgets.
67
68
`tkinter.tix ` provides bindings for it, and official Python binary releases
68
69
come with it bundled. It's deprecated in favor of Ttk.
71
72
Tkinter Modules
72
73
^^^^^^^^^^^^^^^
73
74
74
- :mod: `tkinter ` has the core functionality and the regular Tk widgets.
75
- Unless you're using the additional widgets, this will be all
75
+ :mod: `tkinter ` has the core functionality and the bindings for regular Tk
76
+ widgets. Unless you're using the additional widgets, this will be all
76
77
that you really need.
77
78
78
79
:mod: `tkinter.ttk ` and :mod: `tkinter.tix ` have classes for extra
79
80
widgets from those families. Ttk is intended to be the new standard widget
80
81
set with a more modern look, but as of this writing, it doesn't yet have
81
82
replacements for all the classical widgets.
82
83
83
- The Tk interface is located in a C module named :mod: `_tkinter `.
84
+ The core Tcl/ Tk interface is located in a C module named :mod: `_tkinter `.
84
85
This module directly interfaces with Tcl/Tk via their C interfaces and
85
86
shouldn't be used directly by application programmers save for a few functions.
86
87
It is usually a shared library (or DLL), but might in some cases be statically
87
88
linked with the Python interpreter.
88
89
89
- In addition to the Tk interface module, :mod: `tkinter ` includes a number of
90
- Python modules, :mod: `tkinter.constants ` being one of the most important.
91
- Importing :mod: `tkinter ` will automatically import :mod: `tkinter.constants `,
92
- so, usually, to use Tkinter all you need is a simple import statement::
93
-
94
- import tkinter
95
-
96
- Or, more often::
97
-
98
- from tkinter import *
99
-
100
90
101
91
Threading model
102
92
---------------
@@ -118,7 +108,7 @@ predefined "event handler".
118
108
Likewise, for any lengthy tasks, the UI thread can launch worker threads that
119
109
report back on their progress via the same event queue.
120
110
121
- Tkinter strives to provide the best of both worlds. The "moderm " multithreaded
111
+ Tkinter strives to provide the best of both worlds. The "modern " multithreaded
122
112
GUI model is the primary mode of execution, but pumping messages manually
123
113
instead is also supported. What is more important, any Tkinter calls can be
124
114
made from any Python threads, only subject to Tcl's architectural restictions:
@@ -141,7 +131,21 @@ made from any Python threads, only subject to Tcl's architectural restictions:
141
131
142
132
* A few select functions can only be called from the interpreter thread.
143
133
144
-
134
+ Tcl event queue is per-thread rather than per-interpreter. For nonthreaded Tcl,
135
+ there's only one global queue shared by all interpreters; for threaded Tcl,
136
+ one queue per OS thread that's shared by all interpreters bound to that thread.
137
+ So, when an event processing function like :func: `Tk.mainloop ` is called, it
138
+ will process events not only for the calling :class: `Tk ` instance
139
+ but for all whose interpreters share the queue.
140
+ Events handlers will be called within the same Tcl interpreter that they were
141
+ bound to as per the `bind <https://www.tcl.tk/man/tcl8.6/TkCmd/bind.htm >`_ man
142
+ page, but any exceptions will be raised from the event processing function.
143
+ There's no harm in calling :func: `mainloop ` for two :class: `Tk`s at the same
144
+ time: with nonthreaded Tcl, they will take turns handling events, and with
145
+ threaded Tcl, this is only allowed if the :class:`Tk`s are associated with
146
+ different threads anyway.
147
+
148
+
145
149
Module contents
146
150
---------------
147
151
@@ -218,7 +222,7 @@ Module contents
218
222
219
223
.. class :: Variable(master=None, value=None, name=None)
220
224
221
- Represent a Tcl global variable bound to *master * widget's value via the
225
+ Represents a Tcl global variable bound to *master * widget's value via the
222
226
`textVariable option
223
227
<https://www.tcl.tk/man/tcl8.6/TkCmd/options.htm#M-textvariable> `_.
224
228
0 commit comments