<li><a class="reference" href="#how-do-i-freeze-tkinter-applications" id="id12" name="id12">2.1 How do I freeze Tkinter applications?</a></li>
<li><a class="reference" href="#can-i-have-tk-events-handled-while-waiting-for-i-o" id="id13" name="id13">2.2 Can I have Tk events handled while waiting for I/O?</a></li>
<li><a class="reference" href="#i-can-t-get-key-bindings-to-work-in-tkinter-why" id="id14" name="id14">2.3 I can't get key bindings to work in Tkinter: why?</a></li>
</ul>
</li>
</ul>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id1" id="general-gui-questions" name="general-gui-questions">1 General GUI Questions</a></h1>
<div class="section">
<h2><a class="toc-backref" href="#id2" id="what-platform-independent-gui-toolkits-exist-for-python" name="what-platform-independent-gui-toolkits-exist-for-python">1.1 What platform-independent GUI toolkits exist for Python?</a></h2>
<p>Depending on what platform(s) you are aiming at, there are several.</p>
<p>There are bindings available for the Qt toolkit (<a class="reference" href="http://www.riverbankcomputing.co.uk/pyqt/">PyQt</a>) and for KDE (PyKDE).
If you're writing open source software, you don't need to pay for
PyQt, but if you want to write proprietary applications, you must buy
a PyQt license from <a class="reference" href="http://www.riverbankcomputing.co.uk">Riverbank Computing</a> and a Qt license from
<h2><a class="toc-backref" href="#id12" id="how-do-i-freeze-tkinter-applications" name="how-do-i-freeze-tkinter-applications">2.1 How do I freeze Tkinter applications?</a></h2>
<p>Freeze is a tool to create stand-alone applications. When freezing
Tkinter applications, the applications will not be truly stand-alone,
as the application will still need the Tcl and Tk libraries.</p>
<p>One solution is to ship the application with the tcl and tk libraries,
and point to them at run-time using the TCL_LIBRARY and TK_LIBRARY
environment variables.</p>
<p>To get truly stand-alone applications, the Tcl scripts that form
the library have to be integrated into the application as well. One
tool supporting that is SAM (stand-alone modules), which is part
of the Tix distribution (<a class="reference" href="http://tix.mne.com">http://tix.mne.com</a>). Build Tix with SAM
enabled, perform the appropriate call to Tclsam_init etc inside
Python's Modules/tkappinit.c, and link with libtclsam
and libtksam (you might include the Tix libraries as well).</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id13" id="can-i-have-tk-events-handled-while-waiting-for-i-o" name="can-i-have-tk-events-handled-while-waiting-for-i-o">2.2 Can I have Tk events handled while waiting for I/O?</a></h2>
<p>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
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:</p>
<pre class="literal-block">
from Tkinter import tkinter
tkinter.createfilehandler(file, mask, callback)
</pre>
<p>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:</p>
<pre class="literal-block">
callback(file, mask)
</pre>
<p>You must unregister the callback when you're done, using</p>
<pre class="literal-block">
tkinter.deletefilehandler(file)
</pre>
<p>Note: since you don't know <em>how many bytes</em> 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 recv() or recvfrom() methods will work fine; for other
files, use os.read(file.fileno(), maxbytecount).</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id14" id="i-can-t-get-key-bindings-to-work-in-tkinter-why" name="i-can-t-get-key-bindings-to-work-in-tkinter-why">2.3 I can't get key bindings to work in Tkinter: why?</a></h2>
<p>An often-heard complaint is that event handlers bound to events
with the bind() method don't get handled even when the appropriate
key is pressed.</p>
<p>The most common cause is that the widget to which the binding applies
doesn't have "keyboard focus". Check out the Tk documentation
for the focus command. Usually a widget is given the keyboard
focus by clicking in it (but not for labels; see the takefocus