diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2015-05-17 18:49:20 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2015-05-17 18:49:20 (GMT) |
commit | 84924e6e9218eeba922d7f709ff660e83ecc8f68 (patch) | |
tree | b1baff796e3abde5af31b81b0e5000896a109830 /Doc/faq | |
parent | 4b2c468e7464dc29700b50afcfc0bf101bea7fb8 (diff) | |
download | cpython-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/faq')
-rw-r--r-- | Doc/faq/gui.rst | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/Doc/faq/gui.rst b/Doc/faq/gui.rst index 5e1d8be..44e5908 100644 --- a/Doc/faq/gui.rst +++ b/Doc/faq/gui.rst @@ -125,30 +125,11 @@ might include the Tix libraries as well). Can I have Tk events handled while waiting for I/O? --------------------------------------------------- -Yes, and you don't even need threads! But you'll have to restructure your I/O +On platforms other than Windows, yes, and you don't even +need threads! But you'll have to restructure your I/O code a bit. Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, which allows you to register a callback function which will be called from the Tk mainloop when -I/O is possible on a file descriptor. Here's what you need:: - - from Tkinter import tkinter - tkinter.createfilehandler(file, mask, callback) - -The file may be a Python file or socket object (actually, anything with a -fileno() method), or an integer file descriptor. The mask is one of the -constants tkinter.READABLE or tkinter.WRITABLE. The callback is called as -follows:: - - callback(file, mask) - -You must unregister the callback when you're done, using :: - - tkinter.deletefilehandler(file) - -Note: since you don't know *how many bytes* are available for reading, you can't -use the Python file object's read or readline methods, since these will insist -on reading a predefined number of bytes. For sockets, the :meth:`recv` or -:meth:`recvfrom` methods will work fine; for other files, use -``os.read(file.fileno(), maxbytecount)``. +I/O is possible on a file descriptor. See :ref:`tkinter-file-handlers`. I can't get key bindings to work in Tkinter: why? |