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