blob: f809db15a52028a16455da84547e46845f2f9ae0 [file] [log] [blame]
Georg Brandlac6060c2008-05-17 18:44:45 +00001:mod:`tkinter` --- Python interface to Tcl/Tk
Georg Brandl116aa622007-08-15 14:28:22 +00002=============================================
3
Georg Brandlac6060c2008-05-17 18:44:45 +00004.. module:: tkinter
Georg Brandl116aa622007-08-15 14:28:22 +00005 :synopsis: Interface to Tcl/Tk for graphical user interfaces
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Georg Brandl116aa622007-08-15 14:28:22 +00007.. moduleauthor:: Guido van Rossum <guido@Python.org>
8
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04009**Source code:** :source:`Lib/tkinter/__init__.py`
10
11--------------
Georg Brandl116aa622007-08-15 14:28:22 +000012
Georg Brandlac6060c2008-05-17 18:44:45 +000013The :mod:`tkinter` package ("Tk interface") is the standard Python interface to
Miss Islington (bot)61ecd3e2021-08-22 11:54:46 -070014the Tcl/Tk GUI toolkit. Both Tk and :mod:`tkinter` are available on most Unix
15platforms, including macOS, as well as on Windows systems.
Andrés Delfino67a8f4f2018-04-25 14:53:58 -030016
17Running ``python -m tkinter`` from the command line should open a window
18demonstrating a simple Tk interface, letting you know that :mod:`tkinter` is
19properly installed on your system, and also showing what version of Tcl/Tk is
20installed, so you can read the Tcl/Tk documentation specific to that version.
Georg Brandl116aa622007-08-15 14:28:22 +000021
Miss Islington (bot)2666d702021-08-11 10:16:10 -070022Tkinter supports a range of Tcl/Tk versions, built either with or
23without thread support. The official Python binary release bundles Tcl/Tk 8.6
24threaded. See the source code for the :mod:`_tkinter` module
25for more information about supported versions.
26
27Tkinter is not a thin wrapper, but adds a fair amount of its own logic to
28make the experience more pythonic. This documentation will concentrate on these
29additions and changes, and refer to the official Tcl/Tk documentation for
30details that are unchanged.
31
Miss Islington (bot)8351df62021-08-23 12:22:29 -070032.. note::
33
34 Tcl/Tk 8.5 (2007) introduced a modern set of themed user interface components
35 along with a new API to use them. Both old and new APIs are still available.
36 Most documentation you will find online still uses the old API and
37 can be woefully outdated.
38
Georg Brandl116aa622007-08-15 14:28:22 +000039.. seealso::
40
Łukasz Langa8e90f152021-08-22 21:04:57 +020041 * `TkDocs <http://tkdocs.com/>`_
42 Extensive tutorial on creating user interfaces with Tkinter. Explains key concepts,
43 and illustrates recommended approaches using the modern API.
Andrés Delfino67a8f4f2018-04-25 14:53:58 -030044
Łukasz Langa8e90f152021-08-22 21:04:57 +020045 * `Tkinter 8.5 reference: a GUI for Python <https://www.tkdocs.com/shipman/>`_
46 Reference documentation for Tkinter 8.5 detailing available classes, methods, and options.
Georg Brandl116aa622007-08-15 14:28:22 +000047
Łukasz Langa8e90f152021-08-22 21:04:57 +020048 Tcl/Tk Resources:
Andrew Svetlove708a8a2012-07-26 17:02:57 +030049
Łukasz Langa8e90f152021-08-22 21:04:57 +020050 * `Tk commands <https://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm>`_
51 Comprehensive reference to each of the underlying Tcl/Tk commands used by Tkinter.
Andrew Svetlove708a8a2012-07-26 17:02:57 +030052
Łukasz Langa8e90f152021-08-22 21:04:57 +020053 * `Tcl/Tk Home Page <https://www.tcl.tk>`_
54 Additional documentation, and links to Tcl/Tk core development.
Andrew Svetlove708a8a2012-07-26 17:02:57 +030055
Łukasz Langa8e90f152021-08-22 21:04:57 +020056 Books:
Andrew Svetlove708a8a2012-07-26 17:02:57 +030057
Łukasz Langa8e90f152021-08-22 21:04:57 +020058 * `Modern Tkinter for Busy Python Developers <https://tkdocs.com/book.html>`_
59 By Mark Roseman. (ISBN 978-1999149567)
Andrew Svetlove708a8a2012-07-26 17:02:57 +030060
Łukasz Langa8e90f152021-08-22 21:04:57 +020061 * `Python and Tkinter Programming <https://www.packtpub.com/product/python-gui-programming-with-tkinter/9781788835886>`_
62 By Alan Moore. (ISBN 978-1788835886)
Andrés Delfino67a8f4f2018-04-25 14:53:58 -030063
Łukasz Langa8e90f152021-08-22 21:04:57 +020064 * `Programming Python <http://learning-python.com/about-pp4e.html>`_
65 By Mark Lutz; has excellent coverage of Tkinter. (ISBN 978-0596158101)
Andrés Delfino67a8f4f2018-04-25 14:53:58 -030066
Łukasz Langa8e90f152021-08-22 21:04:57 +020067 * `Tcl and the Tk Toolkit (2nd edition) <https://www.amazon.com/exec/obidos/ASIN/032133633X>`_
68 By John Ousterhout, inventor of Tcl/Tk, and Ken Jones; does not cover Tkinter. (ISBN 978-0321336330)
Georg Brandl116aa622007-08-15 14:28:22 +000069
70
Miss Islington (bot)2666d702021-08-11 10:16:10 -070071Architecture
72------------
73
74Tcl/Tk is not a single library but rather consists of a few distinct
Miss Islington (bot)e4795102021-08-23 13:08:19 -070075modules, each with separate functionality and its own official
Miss Islington (bot)2666d702021-08-11 10:16:10 -070076documentation. Python's binary releases also ship an add-on module
77together with it.
78
79Tcl
80 Tcl is a dynamic interpreted programming language, just like Python. Though
81 it can be used on its own as a general-purpose programming language, it is
82 most commonly embedded into C applications as a scripting engine or an
83 interface to the Tk toolkit. The Tcl library has a C interface to
84 create and manage one or more instances of a Tcl interpreter, run Tcl
85 commands and scripts in those instances, and add custom commands
86 implemented in either Tcl or C. Each interpreter has an event queue,
87 and there are facilities to send events to it and process them.
88 Unlike Python, Tcl's execution model is designed around cooperative
89 multitasking, and Tkinter bridges this difference
90 (see `Threading model`_ for details).
91
92Tk
93 Tk is a `Tcl package <http://wiki.tcl.tk/37432>`_ implemented in C
94 that adds custom commands to create and manipulate GUI widgets. Each
95 :class:`Tk` object embeds its own Tcl interpreter instance with Tk loaded into
96 it. Tk's widgets are very customizable, though at the cost of a dated appearance.
97 Tk uses Tcl's event queue to generate and process GUI events.
98
99Ttk
100 Themed Tk (Ttk) is a newer family of Tk widgets that provide a much better
101 appearance on different platforms than many of the classic Tk widgets.
102 Ttk is distributed as part of Tk, starting with Tk version 8.5. Python
103 bindings are provided in a separate module, :mod:`tkinter.ttk`.
104
Miss Islington (bot)e4795102021-08-23 13:08:19 -0700105Internally, Tk and Ttk use facilities of the underlying operating system,
106i.e., Xlib on Unix/X11, Cocoa on macOS, GDI on Windows.
107
108When your Python application uses a class in Tkinter, e.g., to create a widget,
109the :mod:`tkinter` module first assembles a Tcl/Tk command string. It passes that
110Tcl command string to an internal :mod:`_tkinter` binary module, which then
111calls the Tcl interpreter to evaluate it. The Tcl interpreter will then call into the
112Tk and/or Ttk packages, which will in turn make calls to Xlib, Cocoa, or GDI.
Miss Islington (bot)2666d702021-08-11 10:16:10 -0700113
114
Georg Brandl116aa622007-08-15 14:28:22 +0000115Tkinter Modules
116---------------
117
Miss Islington (bot)4d1e74f2021-08-22 12:04:24 -0700118Support for Tkinter is spread across several modules. Most applications will need the
119main :mod:`tkinter` module, as well as the :mod:`tkinter.ttk` module, which provides
120the modern themed widget set and API::
Georg Brandl116aa622007-08-15 14:28:22 +0000121
Georg Brandl116aa622007-08-15 14:28:22 +0000122
Georg Brandlac6060c2008-05-17 18:44:45 +0000123 from tkinter import *
Miss Islington (bot)4d1e74f2021-08-22 12:04:24 -0700124 from tkinter import ttk
Georg Brandl116aa622007-08-15 14:28:22 +0000125
126
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
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000133 .. FIXME: The following keyword arguments are currently recognized:
Georg Brandl116aa622007-08-15 14:28:22 +0000134
Georg Brandl116aa622007-08-15 14:28:22 +0000135
136.. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=0)
137
138 The :func:`Tcl` function is a factory function which creates an object much like
139 that created by the :class:`Tk` class, except that it does not initialize the Tk
140 subsystem. This is most often useful when driving the Tcl interpreter in an
141 environment where one doesn't want to create extraneous toplevel windows, or
142 where one cannot (such as Unix/Linux systems without an X server). An object
143 created by the :func:`Tcl` object can have a Toplevel window created (and the Tk
144 subsystem initialized) by calling its :meth:`loadtk` method.
145
Georg Brandl116aa622007-08-15 14:28:22 +0000146
Miss Islington (bot)4d1e74f2021-08-22 12:04:24 -0700147The modules that provide Tk support include:
148
149:mod:`tkinter`
150 Main Tkinter module.
Georg Brandl116aa622007-08-15 14:28:22 +0000151
Georg Brandlac6060c2008-05-17 18:44:45 +0000152:mod:`tkinter.colorchooser`
Georg Brandl116aa622007-08-15 14:28:22 +0000153 Dialog to let the user choose a color.
154
Georg Brandlac6060c2008-05-17 18:44:45 +0000155:mod:`tkinter.commondialog`
Georg Brandl116aa622007-08-15 14:28:22 +0000156 Base class for the dialogs defined in the other modules listed here.
157
Georg Brandlac6060c2008-05-17 18:44:45 +0000158:mod:`tkinter.filedialog`
Georg Brandl116aa622007-08-15 14:28:22 +0000159 Common dialogs to allow the user to specify a file to open or save.
160
Georg Brandlac6060c2008-05-17 18:44:45 +0000161:mod:`tkinter.font`
Georg Brandl116aa622007-08-15 14:28:22 +0000162 Utilities to help work with fonts.
163
Georg Brandlac6060c2008-05-17 18:44:45 +0000164:mod:`tkinter.messagebox`
Georg Brandl116aa622007-08-15 14:28:22 +0000165 Access to standard Tk dialog boxes.
166
Nikhil80428ed2019-09-10 01:55:34 -0700167:mod:`tkinter.scrolledtext`
168 Text widget with a vertical scroll bar built in.
169
Georg Brandlac6060c2008-05-17 18:44:45 +0000170:mod:`tkinter.simpledialog`
Georg Brandl116aa622007-08-15 14:28:22 +0000171 Basic dialogs and convenience functions.
172
Miss Islington (bot)4d1e74f2021-08-22 12:04:24 -0700173:mod:`tkinter.ttk`
174 Themed widget set introduced in Tk 8.5, providing modern alternatives
175 for many of the classic widgets in the main :mod:`tkinter` module.
176
177Additional modules:
178
179:mod:`_tkinter`
180 A binary module that contains the low-level interface to Tcl/Tk.
181 It is automatically imported by the main :mod:`tkinter` module,
182 and should never be used directly by application programmers.
183 It is usually a shared library (or DLL), but might in some cases be
184 statically linked with the Python interpreter.
185
186:mod:`idlelib`
187 Python's Integrated Development and Learning Environment (IDLE). Based
188 on :mod:`tkinter`.
189
190:mod:`tkinter.constants`
191 Symbolic constants that can be used in place of strings when passing
192 various parameters to Tkinter calls. Automatically imported by the
193 main :mod:`tkinter` module.
194
Georg Brandlac6060c2008-05-17 18:44:45 +0000195:mod:`tkinter.dnd`
Miss Islington (bot)4d1e74f2021-08-22 12:04:24 -0700196 (experimental) Drag-and-drop support for :mod:`tkinter`. This will
197 become deprecated when it is replaced with the Tk DND.
198
199:mod:`tkinter.tix`
200 (deprecated) An older third-party Tcl/Tk package that adds several new
201 widgets. Better alternatives for most can be found in :mod:`tkinter.ttk`.
Georg Brandl116aa622007-08-15 14:28:22 +0000202
Georg Brandl23d11d32008-09-21 07:50:52 +0000203:mod:`turtle`
Georg Brandl116aa622007-08-15 14:28:22 +0000204 Turtle graphics in a Tk window.
205
206
207Tkinter Life Preserver
208----------------------
209
210.. sectionauthor:: Matt Conway
211
212
213This section is not designed to be an exhaustive tutorial on either Tk or
214Tkinter. Rather, it is intended as a stop gap, providing some introductory
215orientation on the system.
216
Georg Brandl116aa622007-08-15 14:28:22 +0000217Credits:
218
Georg Brandl116aa622007-08-15 14:28:22 +0000219* Tk was written by John Ousterhout while at Berkeley.
220
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000221* Tkinter was written by Steen Lumholt and Guido van Rossum.
222
Georg Brandl116aa622007-08-15 14:28:22 +0000223* This Life Preserver was written by Matt Conway at the University of Virginia.
224
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000225* The HTML rendering, and some liberal editing, was produced from a FrameMaker
Georg Brandl116aa622007-08-15 14:28:22 +0000226 version by Ken Manheimer.
227
228* Fredrik Lundh elaborated and revised the class interface descriptions, to get
229 them current with Tk 4.2.
230
231* Mike Clarkson converted the documentation to LaTeX, and compiled the User
232 Interface chapter of the reference manual.
233
234
235How To Use This Section
236^^^^^^^^^^^^^^^^^^^^^^^
237
238This section is designed in two parts: the first half (roughly) covers
239background material, while the second half can be taken to the keyboard as a
240handy reference.
241
242When trying to answer questions of the form "how do I do blah", it is often best
Julien Palardae342cf2017-12-05 06:05:33 +0100243to find out how to do "blah" in straight Tk, and then convert this back into the
Georg Brandlac6060c2008-05-17 18:44:45 +0000244corresponding :mod:`tkinter` call. Python programmers can often guess at the
Georg Brandl116aa622007-08-15 14:28:22 +0000245correct Python command by looking at the Tk documentation. This means that in
246order to use Tkinter, you will have to know a little bit about Tk. This document
247can't fulfill that role, so the best we can do is point you to the best
248documentation that exists. Here are some hints:
249
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000250* The authors strongly suggest getting a copy of the Tk man pages.
251 Specifically, the man pages in the ``manN`` directory are most useful.
252 The ``man3`` man pages describe the C interface to the Tk library and thus
253 are not especially helpful for script writers.
Georg Brandl116aa622007-08-15 14:28:22 +0000254
255* Addison-Wesley publishes a book called Tcl and the Tk Toolkit by John
256 Ousterhout (ISBN 0-201-63337-X) which is a good introduction to Tcl and Tk for
257 the novice. The book is not exhaustive, and for many details it defers to the
258 man pages.
259
Georg Brandl48310cd2009-01-03 21:18:54 +0000260* :file:`tkinter/__init__.py` is a last resort for most, but can be a good
Georg Brandlac6060c2008-05-17 18:44:45 +0000261 place to go when nothing else makes sense.
Georg Brandl116aa622007-08-15 14:28:22 +0000262
263
Georg Brandl116aa622007-08-15 14:28:22 +0000264A Simple Hello World Program
265^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266
Georg Brandl116aa622007-08-15 14:28:22 +0000267::
268
Andrew Svetlovd3d7c902012-03-14 21:41:23 -0700269 import tkinter as tk
Georg Brandl116aa622007-08-15 14:28:22 +0000270
Andrew Svetlovd3d7c902012-03-14 21:41:23 -0700271 class Application(tk.Frame):
272 def __init__(self, master=None):
Berker Peksag3093bf12016-07-14 07:32:43 +0300273 super().__init__(master)
Daniel Lovella80af772018-10-30 07:56:07 -0700274 self.master = master
Andrew Svetlovd3d7c902012-03-14 21:41:23 -0700275 self.pack()
Berker Peksag3093bf12016-07-14 07:32:43 +0300276 self.create_widgets()
Georg Brandl116aa622007-08-15 14:28:22 +0000277
Berker Peksag3093bf12016-07-14 07:32:43 +0300278 def create_widgets(self):
Andrew Svetlovd3d7c902012-03-14 21:41:23 -0700279 self.hi_there = tk.Button(self)
280 self.hi_there["text"] = "Hello World\n(click me)"
281 self.hi_there["command"] = self.say_hi
282 self.hi_there.pack(side="top")
Georg Brandl116aa622007-08-15 14:28:22 +0000283
Berker Peksag3093bf12016-07-14 07:32:43 +0300284 self.quit = tk.Button(self, text="QUIT", fg="red",
Daniel Lovella80af772018-10-30 07:56:07 -0700285 command=self.master.destroy)
Berker Peksag3093bf12016-07-14 07:32:43 +0300286 self.quit.pack(side="bottom")
Georg Brandl116aa622007-08-15 14:28:22 +0000287
Andrew Svetlovd3d7c902012-03-14 21:41:23 -0700288 def say_hi(self):
289 print("hi there, everyone!")
Georg Brandl116aa622007-08-15 14:28:22 +0000290
Andrew Svetlovd3d7c902012-03-14 21:41:23 -0700291 root = tk.Tk()
292 app = Application(master=root)
293 app.mainloop()
Georg Brandl116aa622007-08-15 14:28:22 +0000294
295
296A (Very) Quick Look at Tcl/Tk
297-----------------------------
298
299The class hierarchy looks complicated, but in actual practice, application
300programmers almost always refer to the classes at the very bottom of the
301hierarchy.
302
Georg Brandl116aa622007-08-15 14:28:22 +0000303Notes:
304
305* These classes are provided for the purposes of organizing certain functions
306 under one namespace. They aren't meant to be instantiated independently.
307
308* The :class:`Tk` class is meant to be instantiated only once in an application.
309 Application programmers need not instantiate one explicitly, the system creates
310 one whenever any of the other classes are instantiated.
311
312* The :class:`Widget` class is not meant to be instantiated, it is meant only
313 for subclassing to make "real" widgets (in C++, this is called an 'abstract
314 class').
315
316To make use of this reference material, there will be times when you will need
317to know how to read short passages of Tk and how to identify the various parts
318of a Tk command. (See section :ref:`tkinter-basic-mapping` for the
Georg Brandlac6060c2008-05-17 18:44:45 +0000319:mod:`tkinter` equivalents of what's below.)
Georg Brandl116aa622007-08-15 14:28:22 +0000320
321Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are just lists
322of tokens separated by spaces. A Tk widget is just its *class*, the *options*
323that help configure it, and the *actions* that make it do useful things.
324
325To make a widget in Tk, the command is always of the form::
326
327 classCommand newPathname options
328
329*classCommand*
330 denotes which kind of widget to make (a button, a label, a menu...)
331
Serhiy Storchaka913876d2018-10-28 13:41:26 +0200332.. index:: single: . (dot); in Tkinter
333
Georg Brandl116aa622007-08-15 14:28:22 +0000334*newPathname*
335 is the new name for this widget. All names in Tk must be unique. To help
336 enforce this, widgets in Tk are named with *pathnames*, just like files in a
337 file system. The top level widget, the *root*, is called ``.`` (period) and
338 children are delimited by more periods. For example,
339 ``.myApp.controlPanel.okButton`` might be the name of a widget.
340
341*options*
342 configure the widget's appearance and in some cases, its behavior. The options
343 come in the form of a list of flags and values. Flags are preceded by a '-',
344 like Unix shell command flags, and values are put in quotes if they are more
345 than one word.
346
347For example::
348
349 button .fred -fg red -text "hi there"
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000350 ^ ^ \______________________/
Georg Brandl116aa622007-08-15 14:28:22 +0000351 | | |
352 class new options
353 command widget (-opt val -opt val ...)
354
355Once created, the pathname to the widget becomes a new command. This new
356*widget command* is the programmer's handle for getting the new widget to
357perform some *action*. In C, you'd express this as someAction(fred,
358someOptions), in C++, you would express this as fred.someAction(someOptions),
359and in Tk, you say::
360
Georg Brandl48310cd2009-01-03 21:18:54 +0000361 .fred someAction someOptions
Georg Brandl116aa622007-08-15 14:28:22 +0000362
363Note that the object name, ``.fred``, starts with a dot.
364
365As you'd expect, the legal values for *someAction* will depend on the widget's
366class: ``.fred disable`` works if fred is a button (fred gets greyed out), but
367does not work if fred is a label (disabling of labels is not supported in Tk).
368
369The legal values of *someOptions* is action dependent. Some actions, like
370``disable``, require no arguments, others, like a text-entry box's ``delete``
371command, would need arguments to specify what range of text to delete.
372
373
374.. _tkinter-basic-mapping:
375
376Mapping Basic Tk into Tkinter
377-----------------------------
378
379Class commands in Tk correspond to class constructors in Tkinter. ::
380
381 button .fred =====> fred = Button()
382
383The master of an object is implicit in the new name given to it at creation
384time. In Tkinter, masters are specified explicitly. ::
385
386 button .panel.fred =====> fred = Button(panel)
387
388The configuration options in Tk are given in lists of hyphened tags followed by
389values. In Tkinter, options are specified as keyword-arguments in the instance
390constructor, and keyword-args for configure calls or as instance indices, in
391dictionary style, for established instances. See section
392:ref:`tkinter-setting-options` on setting options. ::
393
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000394 button .fred -fg red =====> fred = Button(panel, fg="red")
Georg Brandl116aa622007-08-15 14:28:22 +0000395 .fred configure -fg red =====> fred["fg"] = red
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000396 OR ==> fred.config(fg="red")
Georg Brandl116aa622007-08-15 14:28:22 +0000397
398In Tk, to perform an action on a widget, use the widget name as a command, and
399follow it with an action name, possibly with arguments (options). In Tkinter,
400you call methods on the class instance to invoke actions on the widget. The
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000401actions (methods) that a given widget can perform are listed in
402:file:`tkinter/__init__.py`. ::
Georg Brandl116aa622007-08-15 14:28:22 +0000403
404 .fred invoke =====> fred.invoke()
405
406To give a widget to the packer (geometry manager), you call pack with optional
407arguments. In Tkinter, the Pack class holds all this functionality, and the
408various forms of the pack command are implemented as methods. All widgets in
Georg Brandlac6060c2008-05-17 18:44:45 +0000409:mod:`tkinter` are subclassed from the Packer, and so inherit all the packing
Georg Brandl48310cd2009-01-03 21:18:54 +0000410methods. See the :mod:`tkinter.tix` module documentation for additional
Georg Brandlac6060c2008-05-17 18:44:45 +0000411information on the Form geometry manager. ::
Georg Brandl116aa622007-08-15 14:28:22 +0000412
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000413 pack .fred -side left =====> fred.pack(side="left")
Georg Brandl116aa622007-08-15 14:28:22 +0000414
415
Miss Islington (bot)2666d702021-08-11 10:16:10 -0700416Threading model
417---------------
418
419Python and Tcl/Tk have very different threading models, which :mod:`tkinter`
420tries to bridge. If you use threads, you may need to be aware of this.
421
422A Python interpreter may have many threads associated with it. In Tcl, multiple
423threads can be created, but each thread has a separate Tcl interpreter instance
424associated with it. Threads can also create more than one interpreter instance,
425though each interpreter instance can be used only by the one thread that created it.
426
427Each :class:`Tk` object created by :mod:`tkinter` contains a Tcl interpreter.
428It also keeps track of which thread created that interpreter. Calls to
429:mod:`tkinter` can be made from any Python thread. Internally, if a call comes
430from a thread other than the one that created the :class:`Tk` object, an event
431is posted to the interpreter's event queue, and when executed, the result is
432returned to the calling Python thread.
433
434Tcl/Tk applications are normally event-driven, meaning that after initialization,
435the interpreter runs an event loop (i.e. :func:`Tk.mainloop`) and responds to events.
436Because it is single-threaded, event handlers must respond quickly, otherwise they
437will block other events from being processed. To avoid this, any long-running
438computations should not run in an event handler, but are either broken into smaller
439pieces using timers, or run in another thread. This is different from many GUI
440toolkits where the GUI runs in a completely separate thread from all application
441code including event handlers.
442
443If the Tcl interpreter is not running the event loop and processing events, any
444:mod:`tkinter` calls made from threads other than the one running the Tcl
445interpreter will fail.
446
447A number of special cases exist:
448
449 * Tcl/Tk libraries can be built so they are not thread-aware. In this case,
450 :mod:`tkinter` calls the library from the originating Python thread, even
451 if this is different than the thread that created the Tcl interpreter. A global
452 lock ensures only one call occurs at a time.
453
454 * While :mod:`tkinter` allows you to create more than one instance of a :class:`Tk`
455 object (with its own interpreter), all interpreters that are part of the same
456 thread share a common event queue, which gets ugly fast. In practice, don't create
457 more than one instance of :class:`Tk` at a time. Otherwise, it's best to create
458 them in separate threads and ensure you're running a thread-aware Tcl/Tk build.
459
460 * Blocking event handlers are not the only way to prevent the Tcl interpreter from
461 reentering the event loop. It is even possible to run multiple nested event loops
462 or abandon the event loop entirely. If you're doing anything tricky when it comes
463 to events or threads, be aware of these possibilities.
464
465 * There are a few select :mod:`tkinter` functions that presently work only when
466 called from the thread that created the Tcl interpreter.
467
468
Georg Brandl116aa622007-08-15 14:28:22 +0000469Handy Reference
470---------------
471
472
473.. _tkinter-setting-options:
474
475Setting Options
476^^^^^^^^^^^^^^^
477
478Options control things like the color and border width of a widget. Options can
479be set in three ways:
480
481At object creation time, using keyword arguments
482 ::
483
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000484 fred = Button(self, fg="red", bg="blue")
Georg Brandl116aa622007-08-15 14:28:22 +0000485
486After object creation, treating the option name like a dictionary index
487 ::
488
489 fred["fg"] = "red"
490 fred["bg"] = "blue"
491
492Use the config() method to update multiple attrs subsequent to object creation
493 ::
494
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000495 fred.config(fg="red", bg="blue")
Georg Brandl116aa622007-08-15 14:28:22 +0000496
497For a complete explanation of a given option and its behavior, see the Tk man
498pages for the widget in question.
499
500Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC OPTIONS"
501for each widget. The former is a list of options that are common to many
502widgets, the latter are the options that are idiosyncratic to that particular
503widget. The Standard Options are documented on the :manpage:`options(3)` man
504page.
505
506No distinction between standard and widget-specific options is made in this
507document. Some options don't apply to some kinds of widgets. Whether a given
508widget responds to a particular option depends on the class of the widget;
509buttons have a ``command`` option, labels do not.
510
511The options supported by a given widget are listed in that widget's man page, or
512can be queried at runtime by calling the :meth:`config` method without
513arguments, or by calling the :meth:`keys` method on that widget. The return
514value of these calls is a dictionary whose key is the name of the option as a
515string (for example, ``'relief'``) and whose values are 5-tuples.
516
517Some options, like ``bg`` are synonyms for common options with long names
518(``bg`` is shorthand for "background"). Passing the ``config()`` method the name
519of a shorthand option will return a 2-tuple, not 5-tuple. The 2-tuple passed
520back will contain the name of the synonym and the "real" option (such as
521``('bg', 'background')``).
522
523+-------+---------------------------------+--------------+
524| Index | Meaning | Example |
525+=======+=================================+==============+
526| 0 | option name | ``'relief'`` |
527+-------+---------------------------------+--------------+
528| 1 | option name for database lookup | ``'relief'`` |
529+-------+---------------------------------+--------------+
530| 2 | option class for database | ``'Relief'`` |
531| | lookup | |
532+-------+---------------------------------+--------------+
533| 3 | default value | ``'raised'`` |
534+-------+---------------------------------+--------------+
535| 4 | current value | ``'groove'`` |
536+-------+---------------------------------+--------------+
537
538Example::
539
Collin Winterc79461b2007-09-01 23:34:30 +0000540 >>> print(fred.config())
Serhiy Storchakaf47036c2013-12-24 11:04:36 +0200541 {'relief': ('relief', 'relief', 'Relief', 'raised', 'groove')}
Georg Brandl116aa622007-08-15 14:28:22 +0000542
543Of course, the dictionary printed will include all the options available and
544their values. This is meant only as an example.
545
546
547The Packer
548^^^^^^^^^^
549
550.. index:: single: packing (widgets)
551
Georg Brandl116aa622007-08-15 14:28:22 +0000552The packer is one of Tk's geometry-management mechanisms. Geometry managers
Nathan Mecaf9492020-08-02 22:13:03 -0400553are used to specify the relative positioning of widgets within their container -
554their mutual *master*. In contrast to the more cumbersome *placer* (which is
555used less commonly, and we do not cover here), the packer takes qualitative
556relationship specification - *above*, *to the left of*, *filling*, etc - and
557works everything out to determine the exact placement coordinates for you.
Georg Brandl116aa622007-08-15 14:28:22 +0000558
Georg Brandl116aa622007-08-15 14:28:22 +0000559The size of any *master* widget is determined by the size of the "slave widgets"
560inside. The packer is used to control where slave widgets appear inside the
561master into which they are packed. You can pack widgets into frames, and frames
562into other frames, in order to achieve the kind of layout you desire.
563Additionally, the arrangement is dynamically adjusted to accommodate incremental
564changes to the configuration, once it is packed.
565
566Note that widgets do not appear until they have had their geometry specified
567with a geometry manager. It's a common early mistake to leave out the geometry
568specification, and then be surprised when the widget is created but nothing
569appears. A widget will appear only after it has had, for example, the packer's
570:meth:`pack` method applied to it.
571
572The pack() method can be called with keyword-option/value pairs that control
573where the widget is to appear within its container, and how it is to behave when
574the main application window is resized. Here are some examples::
575
576 fred.pack() # defaults to side = "top"
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000577 fred.pack(side="left")
578 fred.pack(expand=1)
Georg Brandl116aa622007-08-15 14:28:22 +0000579
580
581Packer Options
582^^^^^^^^^^^^^^
583
584For more extensive information on the packer and the options that it can take,
585see the man pages and page 183 of John Ousterhout's book.
586
Georg Brandl48310cd2009-01-03 21:18:54 +0000587anchor
Georg Brandl116aa622007-08-15 14:28:22 +0000588 Anchor type. Denotes where the packer is to place each slave in its parcel.
589
590expand
591 Boolean, ``0`` or ``1``.
592
593fill
594 Legal values: ``'x'``, ``'y'``, ``'both'``, ``'none'``.
595
596ipadx and ipady
597 A distance - designating internal padding on each side of the slave widget.
598
599padx and pady
600 A distance - designating external padding on each side of the slave widget.
601
602side
603 Legal values are: ``'left'``, ``'right'``, ``'top'``, ``'bottom'``.
604
605
606Coupling Widget Variables
607^^^^^^^^^^^^^^^^^^^^^^^^^
608
609The current-value setting of some widgets (like text entry widgets) can be
610connected directly to application variables by using special options. These
611options are ``variable``, ``textvariable``, ``onvalue``, ``offvalue``, and
612``value``. This connection works both ways: if the variable changes for any
613reason, the widget it's connected to will be updated to reflect the new value.
614
Georg Brandlac6060c2008-05-17 18:44:45 +0000615Unfortunately, in the current implementation of :mod:`tkinter` it is not
Georg Brandl116aa622007-08-15 14:28:22 +0000616possible to hand over an arbitrary Python variable to a widget through a
617``variable`` or ``textvariable`` option. The only kinds of variables for which
618this works are variables that are subclassed from a class called Variable,
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000619defined in :mod:`tkinter`.
Georg Brandl116aa622007-08-15 14:28:22 +0000620
621There are many useful subclasses of Variable already defined:
622:class:`StringVar`, :class:`IntVar`, :class:`DoubleVar`, and
623:class:`BooleanVar`. To read the current value of such a variable, call the
Georg Brandl502d9a52009-07-26 15:02:41 +0000624:meth:`get` method on it, and to change its value you call the :meth:`!set`
Georg Brandl116aa622007-08-15 14:28:22 +0000625method. If you follow this protocol, the widget will always track the value of
626the variable, with no further intervention on your part.
627
628For example::
629
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100630 import tkinter as tk
631
632 class App(tk.Frame):
633 def __init__(self, master):
Berker Peksag3093bf12016-07-14 07:32:43 +0300634 super().__init__(master)
Georg Brandl116aa622007-08-15 14:28:22 +0000635 self.pack()
636
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100637 self.entrythingy = tk.Entry()
Georg Brandl116aa622007-08-15 14:28:22 +0000638 self.entrythingy.pack()
639
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100640 # Create the application variable.
641 self.contents = tk.StringVar()
642 # Set it to some value.
Georg Brandl116aa622007-08-15 14:28:22 +0000643 self.contents.set("this is a variable")
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100644 # Tell the entry widget to watch this variable.
Georg Brandl116aa622007-08-15 14:28:22 +0000645 self.entrythingy["textvariable"] = self.contents
646
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100647 # Define a callback for when the user hits return.
648 # It prints the current value of the variable.
Georg Brandl116aa622007-08-15 14:28:22 +0000649 self.entrythingy.bind('<Key-Return>',
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100650 self.print_contents)
Georg Brandl116aa622007-08-15 14:28:22 +0000651
652 def print_contents(self, event):
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100653 print("Hi. The current entry content is:",
Collin Winterc79461b2007-09-01 23:34:30 +0000654 self.contents.get())
Georg Brandl116aa622007-08-15 14:28:22 +0000655
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100656 root = tk.Tk()
657 myapp = App(root)
658 myapp.mainloop()
Georg Brandl116aa622007-08-15 14:28:22 +0000659
660The Window Manager
661^^^^^^^^^^^^^^^^^^
662
663.. index:: single: window manager (widgets)
664
Georg Brandl116aa622007-08-15 14:28:22 +0000665In Tk, there is a utility command, ``wm``, for interacting with the window
666manager. Options to the ``wm`` command allow you to control things like titles,
Georg Brandlac6060c2008-05-17 18:44:45 +0000667placement, icon bitmaps, and the like. In :mod:`tkinter`, these commands have
Georg Brandl116aa622007-08-15 14:28:22 +0000668been implemented as methods on the :class:`Wm` class. Toplevel widgets are
669subclassed from the :class:`Wm` class, and so can call the :class:`Wm` methods
670directly.
671
672To get at the toplevel window that contains a given widget, you can often just
673refer to the widget's master. Of course if the widget has been packed inside of
674a frame, the master won't represent a toplevel window. To get at the toplevel
675window that contains an arbitrary widget, you can call the :meth:`_root` method.
676This method begins with an underscore to denote the fact that this function is
677part of the implementation, and not an interface to Tk functionality.
678
Georg Brandl116aa622007-08-15 14:28:22 +0000679Here are some examples of typical usage::
680
Berker Peksag3093bf12016-07-14 07:32:43 +0300681 import tkinter as tk
Georg Brandl116aa622007-08-15 14:28:22 +0000682
Berker Peksag3093bf12016-07-14 07:32:43 +0300683 class App(tk.Frame):
684 def __init__(self, master=None):
685 super().__init__(master)
686 self.pack()
Georg Brandl116aa622007-08-15 14:28:22 +0000687
688 # create the application
689 myapp = App()
690
691 #
692 # here are method calls to the window manager class
693 #
694 myapp.master.title("My Do-Nothing Application")
695 myapp.master.maxsize(1000, 400)
696
697 # start the program
698 myapp.mainloop()
699
700
701Tk Option Data Types
702^^^^^^^^^^^^^^^^^^^^
703
704.. index:: single: Tk Option Data Types
705
Georg Brandl116aa622007-08-15 14:28:22 +0000706anchor
707 Legal values are points of the compass: ``"n"``, ``"ne"``, ``"e"``, ``"se"``,
708 ``"s"``, ``"sw"``, ``"w"``, ``"nw"``, and also ``"center"``.
709
710bitmap
711 There are eight built-in, named bitmaps: ``'error'``, ``'gray25'``,
712 ``'gray50'``, ``'hourglass'``, ``'info'``, ``'questhead'``, ``'question'``,
713 ``'warning'``. To specify an X bitmap filename, give the full path to the file,
714 preceded with an ``@``, as in ``"@/usr/contrib/bitmap/gumby.bit"``.
715
716boolean
Serhiy Storchakaa4d170d2013-12-23 18:20:51 +0200717 You can pass integers 0 or 1 or the strings ``"yes"`` or ``"no"``.
Georg Brandl116aa622007-08-15 14:28:22 +0000718
719callback
720 This is any Python function that takes no arguments. For example::
721
722 def print_it():
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000723 print("hi there")
Georg Brandl116aa622007-08-15 14:28:22 +0000724 fred["command"] = print_it
725
726color
727 Colors can be given as the names of X colors in the rgb.txt file, or as strings
728 representing RGB values in 4 bit: ``"#RGB"``, 8 bit: ``"#RRGGBB"``, 12 bit"
729 ``"#RRRGGGBBB"``, or 16 bit ``"#RRRRGGGGBBBB"`` ranges, where R,G,B here
730 represent any legal hex digit. See page 160 of Ousterhout's book for details.
731
732cursor
733 The standard X cursor names from :file:`cursorfont.h` can be used, without the
734 ``XC_`` prefix. For example to get a hand cursor (:const:`XC_hand2`), use the
735 string ``"hand2"``. You can also specify a bitmap and mask file of your own.
736 See page 179 of Ousterhout's book.
737
738distance
739 Screen distances can be specified in either pixels or absolute distances.
740 Pixels are given as numbers and absolute distances as strings, with the trailing
741 character denoting units: ``c`` for centimetres, ``i`` for inches, ``m`` for
742 millimetres, ``p`` for printer's points. For example, 3.5 inches is expressed
743 as ``"3.5i"``.
744
745font
746 Tk uses a list font name format, such as ``{courier 10 bold}``. Font sizes with
747 positive numbers are measured in points; sizes with negative numbers are
748 measured in pixels.
749
750geometry
751 This is a string of the form ``widthxheight``, where width and height are
752 measured in pixels for most widgets (in characters for widgets displaying text).
753 For example: ``fred["geometry"] = "200x100"``.
754
755justify
756 Legal values are the strings: ``"left"``, ``"center"``, ``"right"``, and
757 ``"fill"``.
758
759region
760 This is a string with four space-delimited elements, each of which is a legal
761 distance (see above). For example: ``"2 3 4 5"`` and ``"3i 2i 4.5i 2i"`` and
762 ``"3c 2c 4c 10.43c"`` are all legal regions.
763
764relief
765 Determines what the border style of a widget will be. Legal values are:
766 ``"raised"``, ``"sunken"``, ``"flat"``, ``"groove"``, and ``"ridge"``.
767
768scrollcommand
Georg Brandl502d9a52009-07-26 15:02:41 +0000769 This is almost always the :meth:`!set` method of some scrollbar widget, but can
Georg Brandl59b44722010-12-30 22:12:40 +0000770 be any widget method that takes a single argument.
Georg Brandl116aa622007-08-15 14:28:22 +0000771
Nikhil80428ed2019-09-10 01:55:34 -0700772wrap
Georg Brandl116aa622007-08-15 14:28:22 +0000773 Must be one of: ``"none"``, ``"char"``, or ``"word"``.
774
Nikhil80428ed2019-09-10 01:55:34 -0700775.. _Bindings-and-Events:
Georg Brandl116aa622007-08-15 14:28:22 +0000776
777Bindings and Events
778^^^^^^^^^^^^^^^^^^^
779
780.. index::
781 single: bind (widgets)
782 single: events (widgets)
783
Georg Brandl116aa622007-08-15 14:28:22 +0000784The bind method from the widget command allows you to watch for certain events
785and to have a callback function trigger when that event type occurs. The form
786of the bind method is::
787
788 def bind(self, sequence, func, add=''):
789
790where:
791
792sequence
793 is a string that denotes the target kind of event. (See the bind man page and
794 page 201 of John Ousterhout's book for details).
795
796func
797 is a Python function, taking one argument, to be invoked when the event occurs.
798 An Event instance will be passed as the argument. (Functions deployed this way
799 are commonly known as *callbacks*.)
800
801add
802 is optional, either ``''`` or ``'+'``. Passing an empty string denotes that
803 this binding is to replace any other bindings that this event is associated
804 with. Passing a ``'+'`` means that this function is to be added to the list
805 of functions bound to this event type.
806
807For example::
808
Berker Peksag3093bf12016-07-14 07:32:43 +0300809 def turn_red(self, event):
Georg Brandl116aa622007-08-15 14:28:22 +0000810 event.widget["activeforeground"] = "red"
811
Berker Peksag3093bf12016-07-14 07:32:43 +0300812 self.button.bind("<Enter>", self.turn_red)
Georg Brandl116aa622007-08-15 14:28:22 +0000813
814Notice how the widget field of the event is being accessed in the
Berker Peksag3093bf12016-07-14 07:32:43 +0300815``turn_red()`` callback. This field contains the widget that caught the X
Georg Brandl116aa622007-08-15 14:28:22 +0000816event. The following table lists the other event fields you can access, and how
817they are denoted in Tk, which can be useful when referring to the Tk man pages.
Georg Brandl116aa622007-08-15 14:28:22 +0000818
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000819+----+---------------------+----+---------------------+
820| Tk | Tkinter Event Field | Tk | Tkinter Event Field |
821+====+=====================+====+=====================+
822| %f | focus | %A | char |
823+----+---------------------+----+---------------------+
824| %h | height | %E | send_event |
825+----+---------------------+----+---------------------+
826| %k | keycode | %K | keysym |
827+----+---------------------+----+---------------------+
828| %s | state | %N | keysym_num |
829+----+---------------------+----+---------------------+
830| %t | time | %T | type |
831+----+---------------------+----+---------------------+
832| %w | width | %W | widget |
833+----+---------------------+----+---------------------+
834| %x | x | %X | x_root |
835+----+---------------------+----+---------------------+
836| %y | y | %Y | y_root |
837+----+---------------------+----+---------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000838
839
840The index Parameter
841^^^^^^^^^^^^^^^^^^^
842
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000843A number of widgets require "index" parameters to be passed. These are used to
Georg Brandl116aa622007-08-15 14:28:22 +0000844point at a specific place in a Text widget, or to particular characters in an
845Entry widget, or to particular menu items in a Menu widget.
846
Georg Brandl116aa622007-08-15 14:28:22 +0000847Entry widget indexes (index, view index, etc.)
848 Entry widgets have options that refer to character positions in the text being
Georg Brandlac6060c2008-05-17 18:44:45 +0000849 displayed. You can use these :mod:`tkinter` functions to access these special
Georg Brandl116aa622007-08-15 14:28:22 +0000850 points in text widgets:
851
Georg Brandl116aa622007-08-15 14:28:22 +0000852Text widget indexes
853 The index notation for Text widgets is very rich and is best described in the Tk
854 man pages.
855
856Menu indexes (menu.invoke(), menu.entryconfig(), etc.)
857 Some options and methods for menus manipulate specific menu entries. Anytime a
858 menu index is needed for an option or a parameter, you may pass in:
859
860 * an integer which refers to the numeric position of the entry in the widget,
861 counted from the top, starting with 0;
862
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000863 * the string ``"active"``, which refers to the menu position that is currently
Georg Brandl116aa622007-08-15 14:28:22 +0000864 under the cursor;
865
866 * the string ``"last"`` which refers to the last menu item;
867
868 * An integer preceded by ``@``, as in ``@6``, where the integer is interpreted
869 as a y pixel coordinate in the menu's coordinate system;
870
871 * the string ``"none"``, which indicates no menu entry at all, most often used
872 with menu.activate() to deactivate all entries, and finally,
873
874 * a text string that is pattern matched against the label of the menu entry, as
875 scanned from the top of the menu to the bottom. Note that this index type is
876 considered after all the others, which means that matches for menu items
877 labelled ``last``, ``active``, or ``none`` may be interpreted as the above
878 literals, instead.
879
880
881Images
882^^^^^^
883
Andrés Delfino4b685bf2018-04-17 02:34:35 -0300884Images of different formats can be created through the corresponding subclass
885of :class:`tkinter.Image`:
Georg Brandl116aa622007-08-15 14:28:22 +0000886
Andrés Delfino4b685bf2018-04-17 02:34:35 -0300887* :class:`BitmapImage` for images in XBM format.
Georg Brandl116aa622007-08-15 14:28:22 +0000888
Andrés Delfino4b685bf2018-04-17 02:34:35 -0300889* :class:`PhotoImage` for images in PGM, PPM, GIF and PNG formats. The latter
890 is supported starting with Tk 8.6.
Georg Brandl116aa622007-08-15 14:28:22 +0000891
892Either type of image is created through either the ``file`` or the ``data``
893option (other options are available as well).
894
895The image object can then be used wherever an ``image`` option is supported by
896some widget (e.g. labels, buttons, menus). In these cases, Tk will not keep a
897reference to the image. When the last Python reference to the image object is
898deleted, the image data is deleted as well, and Tk will display an empty box
899wherever the image was used.
Terry Jan Reedyd9865632015-05-17 14:49:26 -0400900
Andrés Delfinob81ca282018-04-21 09:17:26 -0300901.. seealso::
902
903 The `Pillow <http://python-pillow.org/>`_ package adds support for
904 formats such as BMP, JPEG, TIFF, and WebP, among others.
Terry Jan Reedyd9865632015-05-17 14:49:26 -0400905
906.. _tkinter-file-handlers:
907
908File Handlers
909-------------
910
911Tk allows you to register and unregister a callback function which will be
912called from the Tk mainloop when I/O is possible on a file descriptor.
913Only one handler may be registered per file descriptor. Example code::
914
915 import tkinter
916 widget = tkinter.Tk()
917 mask = tkinter.READABLE | tkinter.WRITABLE
918 widget.tk.createfilehandler(file, mask, callback)
919 ...
920 widget.tk.deletefilehandler(file)
921
922This feature is not available on Windows.
923
924Since you don't know how many bytes are available for reading, you may not
925want to use the :class:`~io.BufferedIOBase` or :class:`~io.TextIOBase`
926:meth:`~io.BufferedIOBase.read` or :meth:`~io.IOBase.readline` methods,
927since these will insist on reading a predefined number of bytes.
928For sockets, the :meth:`~socket.socket.recv` or
929:meth:`~socket.socket.recvfrom` methods will work fine; for other files,
930use raw reads or ``os.read(file.fileno(), maxbytecount)``.
931
932
933.. method:: Widget.tk.createfilehandler(file, mask, func)
934
935 Registers the file handler callback function *func*. The *file* argument
936 may either be an object with a :meth:`~io.IOBase.fileno` method (such as
937 a file or socket object), or an integer file descriptor. The *mask*
938 argument is an ORed combination of any of the three constants below.
939 The callback is called as follows::
940
941 callback(file, mask)
942
943
944.. method:: Widget.tk.deletefilehandler(file)
945
946 Unregisters a file handler.
947
948
949.. data:: READABLE
950 WRITABLE
951 EXCEPTION
952
Ankit Chandawalac36dbac2020-08-03 05:03:48 +0100953 Constants used in the *mask* arguments.