summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2015-05-17 18:49:20 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2015-05-17 18:49:20 (GMT)
commit84924e6e9218eeba922d7f709ff660e83ecc8f68 (patch)
treeb1baff796e3abde5af31b81b0e5000896a109830 /Doc/library
parent4b2c468e7464dc29700b50afcfc0bf101bea7fb8 (diff)
downloadcpython-84924e6e9218eeba922d7f709ff660e83ecc8f68.zip
cpython-84924e6e9218eeba922d7f709ff660e83ecc8f68.tar.gz
cpython-84924e6e9218eeba922d7f709ff660e83ecc8f68.tar.bz2
Issue #22155: Add File Handlers subsection with createfilehandler to Tkinter
doc. Remove obsolete example from FAQ. Patch by Martin Panter.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/tkinter.rst50
1 files changed, 50 insertions, 0 deletions
diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst
index 846f96e..fa60c15 100644
--- a/Doc/library/tkinter.rst
+++ b/Doc/library/tkinter.rst
@@ -817,3 +817,53 @@ reference to the image. When the last Python reference to the image object is
deleted, the image data is deleted as well, and Tk will display an empty box
wherever the image was used.
+
+.. _tkinter-file-handlers:
+
+File Handlers
+-------------
+
+Tk allows you to register and unregister a callback function which will be
+called from the Tk mainloop when I/O is possible on a file descriptor.
+Only one handler may be registered per file descriptor. Example code::
+
+ import Tkinter
+ widget = Tkinter.Tk()
+ mask = Tkinter.READABLE | Tkinter.WRITABLE
+ widget.tk.createfilehandler(file, mask, callback)
+ ...
+ widget.tk.deletefilehandler(file)
+
+This feature is not available on Windows.
+
+Since you don't know how many bytes are available for reading, you may not
+want to use the :class:`~io.BufferedIOBase` or :class:`~io.TextIOBase`
+:meth:`~io.BufferedIOBase.read` or :meth:`~io.IOBase.readline` methods,
+since these will insist on reading a predefined number of bytes.
+For sockets, the :meth:`~socket.socket.recv` or
+:meth:`~socket.socket.recvfrom` methods will work fine; for other files,
+use raw reads or ``os.read(file.fileno(), maxbytecount)``.
+
+
+.. method:: Widget.tk.createfilehandler(file, mask, func)
+
+ Registers the file handler callback function *func*. The *file* argument
+ may either be an object with a :meth:`~io.IOBase.fileno` method (such as
+ a file or socket object), or an integer file descriptor. The *mask*
+ argument is an ORed combination of any of the three constants below.
+ The callback is called as follows::
+
+ callback(file, mask)
+
+
+.. method:: Widget.tk.deletefilehandler(file)
+
+ Unregisters a file handler.
+
+
+.. data:: READABLE
+ WRITABLE
+ EXCEPTION
+
+ Constants used in the *mask* arguments.
+