home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python / faq / gui.html < prev    next >
Encoding:
Extensible Markup Language  |  2009-04-19  |  16.3 KB  |  463 lines

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
  7. <title>Graphic User Interface FAQ</title>
  8. <meta name="date" content="2003-09-04" />
  9. <style type="text/css">
  10.  
  11. /*
  12. :Author: David Goodger (goodger@python.org)
  13. :Id: $Id: html4css1.css 5196 2007-06-03 20:25:28Z wiemann $
  14. :Copyright: This stylesheet has been placed in the public domain.
  15.  
  16. Default cascading style sheet for the HTML output of Docutils.
  17.  
  18. See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
  19. customize this style sheet.
  20. */
  21.  
  22. /* used to remove borders from tables and images */
  23. .borderless, table.borderless td, table.borderless th {
  24.   border: 0 }
  25.  
  26. table.borderless td, table.borderless th {
  27.   /* Override padding for "table.docutils td" with "! important".
  28.      The right padding separates the table cells. */
  29.   padding: 0 0.5em 0 0 ! important }
  30.  
  31. .first {
  32.   /* Override more specific margin styles with "! important". */
  33.   margin-top: 0 ! important }
  34.  
  35. .last, .with-subtitle {
  36.   margin-bottom: 0 ! important }
  37.  
  38. .hidden {
  39.   display: none }
  40.  
  41. a.toc-backref {
  42.   text-decoration: none ;
  43.   color: black }
  44.  
  45. blockquote.epigraph {
  46.   margin: 2em 5em ; }
  47.  
  48. dl.docutils dd {
  49.   margin-bottom: 0.5em }
  50.  
  51. /* Uncomment (and remove this text!) to get bold-faced definition list terms
  52. dl.docutils dt {
  53.   font-weight: bold }
  54. */
  55.  
  56. div.abstract {
  57.   margin: 2em 5em }
  58.  
  59. div.abstract p.topic-title {
  60.   font-weight: bold ;
  61.   text-align: center }
  62.  
  63. div.admonition, div.attention, div.caution, div.danger, div.error,
  64. div.hint, div.important, div.note, div.tip, div.warning {
  65.   margin: 2em ;
  66.   border: medium outset ;
  67.   padding: 1em }
  68.  
  69. div.admonition p.admonition-title, div.hint p.admonition-title,
  70. div.important p.admonition-title, div.note p.admonition-title,
  71. div.tip p.admonition-title {
  72.   font-weight: bold ;
  73.   font-family: sans-serif }
  74.  
  75. div.attention p.admonition-title, div.caution p.admonition-title,
  76. div.danger p.admonition-title, div.error p.admonition-title,
  77. div.warning p.admonition-title {
  78.   color: red ;
  79.   font-weight: bold ;
  80.   font-family: sans-serif }
  81.  
  82. /* Uncomment (and remove this text!) to get reduced vertical space in
  83.    compound paragraphs.
  84. div.compound .compound-first, div.compound .compound-middle {
  85.   margin-bottom: 0.5em }
  86.  
  87. div.compound .compound-last, div.compound .compound-middle {
  88.   margin-top: 0.5em }
  89. */
  90.  
  91. div.dedication {
  92.   margin: 2em 5em ;
  93.   text-align: center ;
  94.   font-style: italic }
  95.  
  96. div.dedication p.topic-title {
  97.   font-weight: bold ;
  98.   font-style: normal }
  99.  
  100. div.figure {
  101.   margin-left: 2em ;
  102.   margin-right: 2em }
  103.  
  104. div.footer, div.header {
  105.   clear: both;
  106.   font-size: smaller }
  107.  
  108. div.line-block {
  109.   display: block ;
  110.   margin-top: 1em ;
  111.   margin-bottom: 1em }
  112.  
  113. div.line-block div.line-block {
  114.   margin-top: 0 ;
  115.   margin-bottom: 0 ;
  116.   margin-left: 1.5em }
  117.  
  118. div.sidebar {
  119.   margin: 0 0 0.5em 1em ;
  120.   border: medium outset ;
  121.   padding: 1em ;
  122.   background-color: #ffffee ;
  123.   width: 40% ;
  124.   float: right ;
  125.   clear: right }
  126.  
  127. div.sidebar p.rubric {
  128.   font-family: sans-serif ;
  129.   font-size: medium }
  130.  
  131. div.system-messages {
  132.   margin: 5em }
  133.  
  134. div.system-messages h1 {
  135.   color: red }
  136.  
  137. div.system-message {
  138.   border: medium outset ;
  139.   padding: 1em }
  140.  
  141. div.system-message p.system-message-title {
  142.   color: red ;
  143.   font-weight: bold }
  144.  
  145. div.topic {
  146.   margin: 2em }
  147.  
  148. h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
  149. h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
  150.   margin-top: 0.4em }
  151.  
  152. h1.title {
  153.   text-align: center }
  154.  
  155. h2.subtitle {
  156.   text-align: center }
  157.  
  158. hr.docutils {
  159.   width: 75% }
  160.  
  161. img.align-left {
  162.   clear: left }
  163.  
  164. img.align-right {
  165.   clear: right }
  166.  
  167. ol.simple, ul.simple {
  168.   margin-bottom: 1em }
  169.  
  170. ol.arabic {
  171.   list-style: decimal }
  172.  
  173. ol.loweralpha {
  174.   list-style: lower-alpha }
  175.  
  176. ol.upperalpha {
  177.   list-style: upper-alpha }
  178.  
  179. ol.lowerroman {
  180.   list-style: lower-roman }
  181.  
  182. ol.upperroman {
  183.   list-style: upper-roman }
  184.  
  185. p.attribution {
  186.   text-align: right ;
  187.   margin-left: 50% }
  188.  
  189. p.caption {
  190.   font-style: italic }
  191.  
  192. p.credits {
  193.   font-style: italic ;
  194.   font-size: smaller }
  195.  
  196. p.label {
  197.   white-space: nowrap }
  198.  
  199. p.rubric {
  200.   font-weight: bold ;
  201.   font-size: larger ;
  202.   color: maroon ;
  203.   text-align: center }
  204.  
  205. p.sidebar-title {
  206.   font-family: sans-serif ;
  207.   font-weight: bold ;
  208.   font-size: larger }
  209.  
  210. p.sidebar-subtitle {
  211.   font-family: sans-serif ;
  212.   font-weight: bold }
  213.  
  214. p.topic-title {
  215.   font-weight: bold }
  216.  
  217. pre.address {
  218.   margin-bottom: 0 ;
  219.   margin-top: 0 ;
  220.   font-family: serif ;
  221.   font-size: 100% }
  222.  
  223. pre.literal-block, pre.doctest-block {
  224.   margin-left: 2em ;
  225.   margin-right: 2em }
  226.  
  227. span.classifier {
  228.   font-family: sans-serif ;
  229.   font-style: oblique }
  230.  
  231. span.classifier-delimiter {
  232.   font-family: sans-serif ;
  233.   font-weight: bold }
  234.  
  235. span.interpreted {
  236.   font-family: sans-serif }
  237.  
  238. span.option {
  239.   white-space: nowrap }
  240.  
  241. span.pre {
  242.   white-space: pre }
  243.  
  244. span.problematic {
  245.   color: red }
  246.  
  247. span.section-subtitle {
  248.   /* font-size relative to parent (h1..h6 element) */
  249.   font-size: 80% }
  250.  
  251. table.citation {
  252.   border-left: solid 1px gray;
  253.   margin-left: 1px }
  254.  
  255. table.docinfo {
  256.   margin: 2em 4em }
  257.  
  258. table.docutils {
  259.   margin-top: 0.5em ;
  260.   margin-bottom: 0.5em }
  261.  
  262. table.footnote {
  263.   border-left: solid 1px black;
  264.   margin-left: 1px }
  265.  
  266. table.docutils td, table.docutils th,
  267. table.docinfo td, table.docinfo th {
  268.   padding-left: 0.5em ;
  269.   padding-right: 0.5em ;
  270.   vertical-align: top }
  271.  
  272. table.docutils th.field-name, table.docinfo th.docinfo-name {
  273.   font-weight: bold ;
  274.   text-align: left ;
  275.   white-space: nowrap ;
  276.   padding-left: 0 }
  277.  
  278. h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
  279. h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
  280.   font-size: 100% }
  281.  
  282. ul.auto-toc {
  283.   list-style-type: none }
  284.  
  285. </style>
  286. </head>
  287. <body>
  288. <div class="document" id="graphic-user-interface-faq">
  289. <h1 class="title">Graphic User Interface FAQ</h1>
  290. <table class="docinfo" frame="void" rules="none">
  291. <col class="docinfo-name" />
  292. <col class="docinfo-content" />
  293. <tbody valign="top">
  294. <tr><th class="docinfo-name">Date:</th>
  295. <td>2003-09-04</td></tr>
  296. <tr><th class="docinfo-name">Version:</th>
  297. <td>6607</td></tr>
  298. <tr class="field"><th class="docinfo-name">Web site:</th><td class="field-body"><a class="reference external" href="http://www.python.org/">http://www.python.org/</a></td>
  299. </tr>
  300. </tbody>
  301. </table>
  302. <div class="contents topic" id="contents">
  303. <p class="topic-title first">Contents</p>
  304. <ul class="auto-toc simple">
  305. <li><a class="reference internal" href="#general-gui-questions" id="id1">1   General GUI Questions</a><ul class="auto-toc">
  306. <li><a class="reference internal" href="#what-platform-independent-gui-toolkits-exist-for-python" id="id2">1.1   What platform-independent GUI toolkits exist for Python?</a><ul class="auto-toc">
  307. <li><a class="reference internal" href="#tkinter" id="id3">1.1.1   Tkinter</a></li>
  308. <li><a class="reference internal" href="#wxwindows" id="id4">1.1.2   wxWindows</a></li>
  309. <li><a class="reference internal" href="#qt" id="id5">1.1.3   Qt</a></li>
  310. <li><a class="reference internal" href="#gtk" id="id6">1.1.4   GTk+</a></li>
  311. <li><a class="reference internal" href="#fltk" id="id7">1.1.5   FLTK</a></li>
  312. <li><a class="reference internal" href="#fox" id="id8">1.1.6   FOX</a></li>
  313. <li><a class="reference internal" href="#opengl" id="id9">1.1.7   OpenGL</a></li>
  314. </ul>
  315. </li>
  316. <li><a class="reference internal" href="#what-platform-specific-gui-toolkits-exist-for-python" id="id10">1.2   What platform-specific GUI toolkits exist for Python?</a></li>
  317. </ul>
  318. </li>
  319. <li><a class="reference internal" href="#tkinter-questions" id="id11">2   Tkinter questions</a><ul class="auto-toc">
  320. <li><a class="reference internal" href="#how-do-i-freeze-tkinter-applications" id="id12">2.1   How do I freeze Tkinter applications?</a></li>
  321. <li><a class="reference internal" href="#can-i-have-tk-events-handled-while-waiting-for-i-o" id="id13">2.2   Can I have Tk events handled while waiting for I/O?</a></li>
  322. <li><a class="reference internal" href="#i-can-t-get-key-bindings-to-work-in-tkinter-why" id="id14">2.3   I can't get key bindings to work in Tkinter: why?</a></li>
  323. </ul>
  324. </li>
  325. </ul>
  326. </div>
  327. <div class="section" id="general-gui-questions">
  328. <h1><a class="toc-backref" href="#id1">1   General GUI Questions</a></h1>
  329. <div class="section" id="what-platform-independent-gui-toolkits-exist-for-python">
  330. <h2><a class="toc-backref" href="#id2">1.1   What platform-independent GUI toolkits exist for Python?</a></h2>
  331. <p>Depending on what platform(s) you are aiming at, there are several.</p>
  332. <div class="section" id="tkinter">
  333. <h3><a class="toc-backref" href="#id3">1.1.1   Tkinter</a></h3>
  334. <p>Standard builds of Python include an object-oriented interface to the
  335. Tcl/Tk widget set, called Tkinter.  This is probably the easiest to
  336. install and use.  For more info about Tk, including pointers to the
  337. source, see the Tcl/Tk home page at <a class="reference external" href="http://www.tcl.tk">http://www.tcl.tk</a>.  Tcl/Tk is
  338. fully portable to the MacOS, Windows, and Unix platforms.</p>
  339. </div>
  340. <div class="section" id="wxwindows">
  341. <h3><a class="toc-backref" href="#id4">1.1.2   wxWindows</a></h3>
  342. <p>wxWindows is a portable GUI class library written in C++ that's a
  343. portable interface to various platform-specific libraries; wxPython is
  344. a Python interface to wxWindows.  wxWindows supports Windows and MacOS;
  345. on Unix variants, it supports both GTk+ and Motif toolkits.
  346. wxWindows preserves the look and feel of the underlying graphics
  347. toolkit, and there is quite a rich widget set and collection of GDI
  348. classes.  See <a class="reference external" href="http://www.wxwindows.org">the wxWindows page</a> for more
  349. details.</p>
  350. <p><a class="reference external" href="http://alldunn.com/wxPython">wxPython</a> is an extension module that
  351. wraps many of the wxWindows C++ classes, and is quickly gaining
  352. popularity amongst Python developers.  You can get wxPython as part of
  353. the source or CVS distribution of wxWindows, or directly from its home
  354. page.</p>
  355. </div>
  356. <div class="section" id="qt">
  357. <h3><a class="toc-backref" href="#id5">1.1.3   Qt</a></h3>
  358. <p>There are bindings available for the Qt toolkit (<a class="reference external" href="http://www.riverbankcomputing.co.uk/pyqt/">PyQt</a>) and for KDE (PyKDE).
  359. If you're writing open source software, you don't need to pay for
  360. PyQt, but if you want to write proprietary applications, you must buy
  361. a PyQt license from <a class="reference external" href="http://www.riverbankcomputing.co.uk">Riverbank Computing</a> and a Qt license from
  362. <a class="reference external" href="http://www.trolltech.com">Trolltech</a>.</p>
  363. </div>
  364. <div class="section" id="gtk">
  365. <h3><a class="toc-backref" href="#id6">1.1.4   GTk+</a></h3>
  366. <p>PyGTk bindings for the <a class="reference external" href="http://www.gtk.org">GTk+ toolkit</a> have been
  367. implemented by by James Henstridge; see
  368. <a class="reference external" href="ftp://ftp.gtk.org/pub/gtk/python/">ftp://ftp.gtk.org/pub/gtk/python/</a>.</p>
  369. </div>
  370. <div class="section" id="fltk">
  371. <h3><a class="toc-backref" href="#id7">1.1.5   FLTK</a></h3>
  372. <p>Python bindings for <a class="reference external" href="http://www.fltk.org">the FLTK toolkit</a>, a simple yet powerful
  373. and mature cross-platform windowing system, are available from <a class="reference external" href="http://pyfltk.sourceforge.net">the
  374. PyFLTK project</a>.</p>
  375. </div>
  376. <div class="section" id="fox">
  377. <h3><a class="toc-backref" href="#id8">1.1.6   FOX</a></h3>
  378. <p>A wrapper for <a class="reference external" href="http://www.fox-toolkit.org/">the FOX toolkit</a>
  379. called <a class="reference external" href="http://fxpy.sourceforge.net/">FXpy</a> is available.
  380. FOX supports both Unix variants and Windows.</p>
  381. </div>
  382. <div class="section" id="opengl">
  383. <h3><a class="toc-backref" href="#id9">1.1.7   OpenGL</a></h3>
  384. <p>For OpenGL bindings, see <a class="reference external" href="http://pyopengl.sourceforge.net">PyOpenGL</a>.</p>
  385. </div>
  386. </div>
  387. <div class="section" id="what-platform-specific-gui-toolkits-exist-for-python">
  388. <h2><a class="toc-backref" href="#id10">1.2   What platform-specific GUI toolkits exist for Python?</a></h2>
  389. <p><a class="reference external" href="http://www.python.org/download/download_mac.html">The Mac port</a> by
  390. Jack Jansen has a rich and ever-growing set of modules that support
  391. the native Mac toolbox calls.  The port includes support for MacOS9
  392. and MacOS X's Carbon libraries.  By installing the <a class="reference external" href="http://pyobjc.sourceforge.net">PyObjc Objective-C
  393. bridge</a>, Python programs can use
  394. MacOS X's Cocoa libraries. See the documentation that comes with the
  395. Mac port.</p>
  396. <p><a class="reference external" href="http://www.python.org/windows">Pythonwin</a> by Mark Hammond
  397. includes an interface to the Microsoft Foundation
  398. Classes and a Python programming environment using it that's written
  399. mostly in Python.</p>
  400. </div>
  401. </div>
  402. <div class="section" id="tkinter-questions">
  403. <h1><a class="toc-backref" href="#id11">2   Tkinter questions</a></h1>
  404. <div class="section" id="how-do-i-freeze-tkinter-applications">
  405. <h2><a class="toc-backref" href="#id12">2.1   How do I freeze Tkinter applications?</a></h2>
  406. <p>Freeze is a tool to create stand-alone applications.  When freezing
  407. Tkinter applications, the applications will not be truly stand-alone,
  408. as the application will still need the Tcl and Tk libraries.</p>
  409. <p>One solution is to ship the application with the tcl and tk libraries,
  410. and point to them at run-time using the TCL_LIBRARY and TK_LIBRARY
  411. environment variables.</p>
  412. <p>To get truly stand-alone applications, the Tcl scripts that form
  413. the library have to be integrated into the application as well. One
  414. tool supporting that is SAM (stand-alone modules), which is part
  415. of the Tix distribution (<a class="reference external" href="http://tix.mne.com">http://tix.mne.com</a>). Build Tix with SAM
  416. enabled, perform the appropriate call to Tclsam_init etc inside
  417. Python's Modules/tkappinit.c, and link with libtclsam
  418. and libtksam (you might include the Tix libraries as well).</p>
  419. </div>
  420. <div class="section" id="can-i-have-tk-events-handled-while-waiting-for-i-o">
  421. <h2><a class="toc-backref" href="#id13">2.2   Can I have Tk events handled while waiting for I/O?</a></h2>
  422. <p>Yes, and you don't even need threads!  But you'll have to
  423. restructure your I/O code a bit.  Tk has the equivalent of Xt's
  424. XtAddInput() call, which allows you to register a callback function
  425. which will be called from the Tk mainloop when I/O is possible on a
  426. file descriptor.  Here's what you need:</p>
  427. <pre class="literal-block">
  428. from Tkinter import tkinter
  429. tkinter.createfilehandler(file, mask, callback)
  430. </pre>
  431. <p>The file may be a Python file or socket object (actually, anything
  432. with a fileno() method), or an integer file descriptor.  The mask is
  433. one of the constants tkinter.READABLE or tkinter.WRITABLE.  The
  434. callback is called as follows:</p>
  435. <pre class="literal-block">
  436. callback(file, mask)
  437. </pre>
  438. <p>You must unregister the callback when you're done, using</p>
  439. <pre class="literal-block">
  440. tkinter.deletefilehandler(file)
  441. </pre>
  442. <p>Note: since you don't know <em>how many bytes</em> are available for reading,
  443. you can't use the Python file object's read or readline methods, since
  444. these will insist on reading a predefined number of bytes.  For
  445. sockets, the recv() or recvfrom() methods will work fine; for other
  446. files, use os.read(file.fileno(), maxbytecount).</p>
  447. </div>
  448. <div class="section" id="i-can-t-get-key-bindings-to-work-in-tkinter-why">
  449. <h2><a class="toc-backref" href="#id14">2.3   I can't get key bindings to work in Tkinter: why?</a></h2>
  450. <p>An often-heard complaint is that event handlers bound to events
  451. with the bind() method don't get handled even when the appropriate
  452. key is pressed.</p>
  453. <p>The most common cause is that the widget to which the binding applies
  454. doesn't have "keyboard focus".  Check out the Tk documentation
  455. for the focus command.  Usually a widget is given the keyboard
  456. focus by clicking in it (but not for labels; see the takefocus
  457. option).</p>
  458. </div>
  459. </div>
  460. </div>
  461. </body>
  462. </html>
  463.