1 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
3 <title>Twisted Documentation: Choosing a Reactor and GUI Toolkit Integration</title>
4 <link href="stylesheet.css" rel="stylesheet" type="text/css"/>
8 <h1 class="title">Choosing a Reactor and GUI Toolkit Integration</h1>
9 <div class="toc"><ol><li><a href="#auto0">Overview</a></li><li><a href="#auto1">Reactor Functionality</a></li><li><a href="#auto2">General Purpose Reactors</a></li><ul><li><a href="#auto3">Select()-based Reactor</a></li></ul><li><a href="#auto4">Platform-Specific Reactors</a></li><ul><li><a href="#auto5">Poll-based Reactor</a></li><li><a href="#auto6">KQueue</a></li><li><a href="#auto7">WaitForMultipleObjects (WFMO) for Win32</a></li><li><a href="#auto8">Input/Output Completion Port (IOCP) for Win32</a></li><li><a href="#auto9">Epoll-based Reactor</a></li></ul><li><a href="#auto10">GUI Integration Reactors</a></li><ul><li><a href="#auto11">GTK+</a></li><li><a href="#auto12">GTK+ 3.0 and GObject Introspection</a></li><li><a href="#auto13">wxPython</a></li><li><a href="#auto14">CoreFoundation</a></li></ul><li><a href="#auto15">Non-Reactor GUI Integration</a></li><ul><li><a href="#auto16">Tkinter</a></li><li><a href="#auto17">PyUI</a></li></ul></ol></div>
13 <h2>Overview<a name="auto0"/></h2>
15 <p>Twisted provides a variety of implementations of the <code class="API"><a href="http://twistedmatrix.com/documents/12.1.0/api/twisted.internet.reactor.html" title="twisted.internet.reactor">twisted.internet.reactor</a></code>. The specialized
16 implementations are suited for different purposes and are
17 designed to integrate better with particular platforms.</p>
19 <p>The <a href="#epoll" shape="rect">epoll()-based reactor</a> is Twisted's default on
20 Linux. Other platforms use <a href="#poll" shape="rect">poll()</a>, or the most
21 cross-platform reactor, <a href="#select" shape="rect">select()</a>.</p>
23 <p>Platform-specific reactor implementations exist for:</p>
26 <li><a href="#poll" shape="rect">Poll for Linux</a></li>
27 <li><a href="#epoll" shape="rect">Epoll for Linux 2.6</a></li>
28 <li><a href="#win32_wfmo" shape="rect">WaitForMultipleObjects (WFMO) for Win32</a></li>
29 <li><a href="#win32_iocp" shape="rect">Input/Output Completion Port (IOCP) for Win32</a></li>
30 <li><a href="#kqueue" shape="rect">KQueue for FreeBSD and Mac OS X</a></li>
31 <li><a href="#cfreactor" shape="rect">CoreFoundation for Mac OS X</a></li>
34 <p>The remaining custom reactor implementations provide support
35 for integrating with the native event loops of various graphical
36 toolkits. This lets your Twisted application use all of the
37 usual Twisted APIs while still being a graphical application.</p>
39 <p>Twisted currently integrates with the following graphical
43 <li><a href="#gtk" shape="rect">GTK+ 2.0</a></li>
44 <li><a href="#gtk3" shape="rect">GTK+ 3.0 and GObject Introspection</a></li>
45 <li><a href="#tkinter" shape="rect">Tkinter</a></li>
46 <li><a href="#wxpython" shape="rect">wxPython</a></li>
47 <li><a href="#win32_wfmo" shape="rect">Win32</a></li>
48 <li><a href="#cfreactor" shape="rect">CoreFoundation</a></li>
49 <li><a href="#pyui" shape="rect">PyUI</a></li>
52 <p>When using applications that are runnable using <code>twistd</code>, e.g.
53 TACs or plugins, there is no need to choose a reactor explicitly, since
54 this can be chosen using <code>twistd</code>'s -r option.</p>
56 <p>In all cases, the event loop is started by calling <code class="python">reactor.run()</code>. In all cases, the event loop
57 should be stopped with <code class="python">reactor.stop()</code>.</p>
59 <p><strong>IMPORTANT:</strong> installing a reactor should be the first thing
60 done in the app, since any code that does
61 <code class="python">from twisted.internet import reactor</code> will automatically
62 install the default reactor if the code hasn't already installed one.</p>
64 <h2>Reactor Functionality<a name="auto1"/></h2>
66 <table border="1" cellpadding="7" cellspacing="0" title="Summary of reactor features">
67 <tr><td colspan="1" rowspan="1"/><th colspan="1" rowspan="1">Status</th><th colspan="1" rowspan="1">TCP</th><th colspan="1" rowspan="1">SSL</th><th colspan="1" rowspan="1">UDP</th><th colspan="1" rowspan="1">Threading</th><th colspan="1" rowspan="1">Processes</th><th colspan="1" rowspan="1">Scheduling</th><th colspan="1" rowspan="1">Platforms</th></tr>
68 <tr><th colspan="1" rowspan="1">select()</th><td colspan="1" rowspan="1">Stable</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Unix, Win32</td></tr>
69 <tr><th colspan="1" rowspan="1">poll</th><td colspan="1" rowspan="1">Stable</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Unix</td></tr>
70 <tr><th colspan="1" rowspan="1">WaitForMultipleObjects (WFMO) for Win32</th><td colspan="1" rowspan="1">Experimental</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Win32</td></tr>
71 <tr><th colspan="1" rowspan="1">Input/Output Completion Port (IOCP) for Win32</th><td colspan="1" rowspan="1">Experimental</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Win32</td></tr>
72 <tr><th colspan="1" rowspan="1">CoreFoundation</th><td colspan="1" rowspan="1">Unmaintained</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Mac OS X</td></tr>
73 <tr><th colspan="1" rowspan="1">epoll</th><td colspan="1" rowspan="1">Stable</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Linux 2.6</td></tr>
74 <tr><th colspan="1" rowspan="1">GTK+</th><td colspan="1" rowspan="1">Stable</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Unix, Win32</td></tr>
75 <tr><th colspan="1" rowspan="1">wx</th><td colspan="1" rowspan="1">Experimental</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Unix, Win32</td></tr>
76 <tr><th colspan="1" rowspan="1">kqueue</th><td colspan="1" rowspan="1">Experimental</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">Y</td><td colspan="1" rowspan="1">FreeBSD</td></tr>
79 <h2>General Purpose Reactors<a name="auto2"/></h2>
81 <h3>Select()-based Reactor<a name="auto3"/></h3><a name="select" shape="rect"/>
83 <p>The <code>select</code> reactor is the default on platforms that don't
84 provide a better alternative that covers all use cases. If
85 the <code>select</code> reactor is desired, it may be installed via:</p>
87 <pre class="python"><p class="py-linenumber">1
91 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">selectreactor</span>
92 <span class="py-src-variable">selectreactor</span>.<span class="py-src-variable">install</span>()
94 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
97 <h2>Platform-Specific Reactors<a name="auto4"/></h2>
99 <h3>Poll-based Reactor<a name="auto5"/></h3><a name="poll" shape="rect"/>
101 <p>The PollReactor will work on any platform that provides <code class="python">select.poll</code>. With larger numbers of connected
102 sockets, it may provide for better performance than the SelectReactor.</p>
104 <pre class="python"><p class="py-linenumber">1
108 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">pollreactor</span>
109 <span class="py-src-variable">pollreactor</span>.<span class="py-src-variable">install</span>()
111 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
114 <h3>KQueue<a name="auto6"/></h3><a name="kqueue" shape="rect"/>
116 <p>The KQueue Reactor allows Twisted to use FreeBSD's kqueue mechanism for
117 event scheduling. See instructions in the <code class="API"><a href="http://twistedmatrix.com/documents/12.1.0/api/twisted.internet.kqreactor.html" title="twisted.internet.kqreactor">twisted.internet.kqreactor</a></code>'s
118 docstring for installation notes.</p>
120 <pre class="python"><p class="py-linenumber">1
124 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">kqreactor</span>
125 <span class="py-src-variable">kqreactor</span>.<span class="py-src-variable">install</span>()
127 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
131 <h3>WaitForMultipleObjects (WFMO) for Win32<a name="auto7"/></h3><a name="win32_wfmo" shape="rect"/>
133 <p>The Win32 reactor is not yet complete and has various limitations
134 and issues that need to be addressed. The reactor supports GUI integration
135 with the win32gui module, so it can be used for native Win32 GUI applications.
138 <pre class="python"><p class="py-linenumber">1
142 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">win32eventreactor</span>
143 <span class="py-src-variable">win32eventreactor</span>.<span class="py-src-variable">install</span>()
145 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
148 <h3>Input/Output Completion Port (IOCP) for Win32<a name="auto8"/></h3><a name="win32_iocp" shape="rect"/>
151 Windows provides a fast, scalable event notification system known as IO
152 Completion Ports, or IOCP for short. Twisted includes a reactor based
153 on IOCP which is nearly complete.
156 <pre class="python"><p class="py-linenumber">1
160 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">iocpreactor</span>
161 <span class="py-src-variable">iocpreactor</span>.<span class="py-src-variable">install</span>()
163 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
166 <h3>Epoll-based Reactor<a name="auto9"/></h3><a name="epoll" shape="rect"/>
168 <p>The EPollReactor will work on any platform that provides
169 <code class="python">epoll</code>, today only Linux 2.6 and over. The
170 implementation of the epoll reactor currently uses the Level Triggered
171 interface, which is basically like poll() but scales much better.</p>
173 <pre class="python"><p class="py-linenumber">1
177 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">epollreactor</span>
178 <span class="py-src-variable">epollreactor</span>.<span class="py-src-variable">install</span>()
180 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
183 <h2>GUI Integration Reactors<a name="auto10"/></h2>
185 <h3>GTK+<a name="auto11"/></h3><a name="gtk" shape="rect"/>
187 <p>Twisted integrates with <a href="http://www.pygtk.org/" shape="rect">PyGTK</a> version
188 2.0 using the <code>gtk2reactor</code>. An example Twisted application that
189 uses GTK+ can be found
190 in <code class="py-filename">doc/core/examples/pbgtk2.py</code>.</p>
192 <p>GTK-2.0 split the event loop out of the GUI toolkit and into a separate
193 module called <q>glib</q>. To run an application using the glib event loop,
194 use the <code>glib2reactor</code>. This will be slightly faster
195 than <code>gtk2reactor</code> (and does not require a working X display),
196 but cannot be used to run GUI applications.</p>
198 <pre class="python"><p class="py-linenumber">1
202 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">gtk2reactor</span> <span class="py-src-comment"># for gtk-2.0</span>
203 <span class="py-src-variable">gtk2reactor</span>.<span class="py-src-variable">install</span>()
205 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
208 <pre class="python"><p class="py-linenumber">1
212 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">glib2reactor</span> <span class="py-src-comment"># for non-GUI apps</span>
213 <span class="py-src-variable">glib2reactor</span>.<span class="py-src-variable">install</span>()
215 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
218 <h3>GTK+ 3.0 and GObject Introspection<a name="auto12"/></h3><a name="gtk3" shape="rect"/>
220 <p>Twisted integrates with <a href="http://gtk.org" shape="rect">GTK+ 3</a> and GObject
221 through <a href="http://live.gnome.org/PyGObject" shape="rect">PyGObject's</a>
222 introspection using the <code>gtk3reactor</code>
223 and <code>gireactor</code> reactors.</p>
225 <pre class="python"><p class="py-linenumber">1
229 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">gtk3reactor</span>
230 <span class="py-src-variable">gtk3reactor</span>.<span class="py-src-variable">install</span>()
232 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
235 <pre class="python"><p class="py-linenumber">1
239 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">gireactor</span> <span class="py-src-comment"># for non-GUI apps</span>
240 <span class="py-src-variable">gireactor</span>.<span class="py-src-variable">install</span>()
242 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
245 <p>GLib 3.0 introduces the concept of <code>GApplication</code>, a class
246 that handles application uniqueness in a cross-platform way and provides
247 its own main loop. Its counterpart <code>GtkApplication</code> also
248 handles application lifetime with respect to open windows. Twisted
249 supports registering these objects with the event loop, which should be
250 done before running the reactor:</p>
252 <pre class="python"><p class="py-linenumber">1
261 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">gtk3reactor</span>
262 <span class="py-src-variable">gtk3reactor</span>.<span class="py-src-variable">install</span>()
264 <span class="py-src-keyword">from</span> <span class="py-src-variable">gi</span>.<span class="py-src-variable">repository</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">Gtk</span>
265 <span class="py-src-variable">app</span> = <span class="py-src-variable">Gtk</span>.<span class="py-src-variable">Application</span>(...)
267 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
268 <span class="py-src-variable">reactor</span>.<span class="py-src-variable">registerGApplication</span>(<span class="py-src-variable">app</span>)
269 <span class="py-src-variable">reactor</span>.<span class="py-src-variable">run</span>()
272 <h3>wxPython<a name="auto13"/></h3><a name="wxpython" shape="rect"/>
274 <p>Twisted currently supports two methods of integrating
275 wxPython. Unfortunately, neither method will work on all wxPython
276 platforms (such as GTK2 or Windows). It seems that the only
277 portable way to integrate with wxPython is to run it in a separate
278 thread. One of these methods may be sufficient if your wx app is
279 limited to a single platform.</p>
281 <p>As with <a href="#tkinter" shape="rect">Tkinter</a>, the support for integrating
282 Twisted with a <a href="http://www.wxpython.org" shape="rect">wxPython</a>
283 application uses specialized support code rather than a simple reactor.</p>
285 <pre class="python"><p class="py-linenumber">1
290 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">wxPython</span>.<span class="py-src-variable">wx</span> <span class="py-src-keyword">import</span> *
291 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">wxsupport</span>, <span class="py-src-variable">reactor</span>
293 <span class="py-src-variable">myWxAppInstance</span> = <span class="py-src-variable">wxApp</span>(<span class="py-src-number">0</span>)
294 <span class="py-src-variable">wxsupport</span>.<span class="py-src-variable">install</span>(<span class="py-src-variable">myWxAppInstance</span>)
297 <p>However, this has issues when running on Windows, so Twisted now
298 comes with alternative wxPython support using a reactor. Using
299 this method is probably better. Initialization is done in two
300 stages. In the first, the reactor is installed:</p>
302 <pre class="python"><p class="py-linenumber">1
306 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">wxreactor</span>
307 <span class="py-src-variable">wxreactor</span>.<span class="py-src-variable">install</span>()
309 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
312 <p>Later, once a <code class="python">wxApp</code> instance has
313 been created, but before <code class="python">reactor.run()</code>
316 <pre class="python"><p class="py-linenumber">1
319 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
320 <span class="py-src-variable">myWxAppInstance</span> = <span class="py-src-variable">wxApp</span>(<span class="py-src-number">0</span>)
321 <span class="py-src-variable">reactor</span>.<span class="py-src-variable">registerWxApp</span>(<span class="py-src-variable">myWxAppInstance</span>)
324 <p>An example Twisted application that uses wxPython can be found
325 in <code class="py-filename">doc/core/examples/wxdemo.py</code>.</p>
327 <h3>CoreFoundation<a name="auto14"/></h3><a name="cfreactor" shape="rect"/>
329 <p>Twisted integrates with <a href="http://pyobjc.sf.net/" shape="rect">PyObjC</a> version 1.0. Sample applications using Cocoa and Twisted
330 are available in the examples directory under
331 <code>doc/core/examples/threadedselect/Cocoa</code>.</p>
333 <pre class="python"><p class="py-linenumber">1
337 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">cfreactor</span>
338 <span class="py-src-variable">cfreactor</span>.<span class="py-src-variable">install</span>()
340 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
343 <h2>Non-Reactor GUI Integration<a name="auto15"/></h2>
345 <h3>Tkinter<a name="auto16"/></h3><a name="tkinter" shape="rect"/>
347 <p>The support for <a href="http://wiki.python.org/moin/TkInter" shape="rect">Tkinter</a> doesn't use a specialized reactor. Instead, there is
348 some specialized support code:</p>
350 <pre class="python"><p class="py-linenumber"> 1
361 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">Tkinter</span> <span class="py-src-keyword">import</span> *
362 <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">tksupport</span>, <span class="py-src-variable">reactor</span>
364 <span class="py-src-variable">root</span> = <span class="py-src-variable">Tk</span>()
366 <span class="py-src-comment"># Install the Reactor support</span>
367 <span class="py-src-variable">tksupport</span>.<span class="py-src-variable">install</span>(<span class="py-src-variable">root</span>)
369 <span class="py-src-comment"># at this point build Tk app as usual using the root object,</span>
370 <span class="py-src-comment"># and start the program with "reactor.run()", and stop it</span>
371 <span class="py-src-comment"># with "reactor.stop()".</span>
374 <h3>PyUI<a name="auto17"/></h3><a name="pyui" shape="rect"/>
376 <p>As with <a href="#tkinter" shape="rect">Tkinter</a>, the support for integrating
377 Twisted with a <a href="http://pyui.sourceforge.net" shape="rect">PyUI</a>
378 application uses specialized support code rather than a simple reactor.</p>
380 <pre class="python"><p class="py-linenumber">1
383 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">pyuisupport</span>, <span class="py-src-variable">reactor</span>
385 <span class="py-src-variable">pyuisupport</span>.<span class="py-src-variable">install</span>(<span class="py-src-variable">args</span>=(<span class="py-src-number">640</span>, <span class="py-src-number">480</span>), <span class="py-src-variable">kw</span>={<span class="py-src-string">'renderer'</span>: <span class="py-src-string">'gl'</span>})
388 <p>An example Twisted application that uses PyUI can be found in <code class="py-filename">doc/core/examples/pyuidemo.py</code>.</p>
392 <p><a href="index.html">Index</a></p>
393 <span class="version">Version: 12.1.0</span>