-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.html
More file actions
323 lines (302 loc) · 19.5 KB
/
gui.html
File metadata and controls
323 lines (302 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!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" lang="zh_TW">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>圖形化使用者界面常見問答集 — Python 3.7.0 說明文件</title>
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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/translations.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.7.0 說明文件 中搜尋"
href="../_static/opensearch.xml"/>
<link rel="author" title="關於這些文件" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜尋" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="為什麼Python被安裝在我的機器上?常見問答集" href="installed.html" />
<link rel="prev" title="FAQ:在 Windows 使用 Python" href="windows.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/faq/gui.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="installed.html" title="為什麼Python被安裝在我的機器上?常見問答集"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="windows.html" title="FAQ:在 Windows 使用 Python"
accesskey="P">上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python 常見問題</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" 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>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="graphic-user-interface-faq">
<h1><a class="toc-backref" href="#id3">圖形化使用者界面常見問答集</a><a class="headerlink" href="#graphic-user-interface-faq" title="本標題的永久連結">¶</a></h1>
<div class="contents topic" id="id1">
<p class="topic-title first">目錄</p>
<ul class="simple">
<li><a class="reference internal" href="#graphic-user-interface-faq" id="id3">圖形化使用者界面常見問答集</a><ul>
<li><a class="reference internal" href="#general-gui-questions" id="id4">常見圖形化使用者界面(GUI) 問題</a></li>
<li><a class="reference internal" href="#what-platform-independent-gui-toolkits-exist-for-python" id="id5">What platform-independent GUI toolkits exist for Python?</a><ul>
<li><a class="reference internal" href="#tkinter" id="id6">Tkinter</a></li>
<li><a class="reference internal" href="#wxwidgets" id="id7">wxWidgets</a></li>
<li><a class="reference internal" href="#qt" id="id8">Qt</a></li>
<li><a class="reference internal" href="#gtk" id="id9">Gtk+</a></li>
<li><a class="reference internal" href="#kivy" id="id10">Kivy</a></li>
<li><a class="reference internal" href="#fltk" id="id11">FLTK</a></li>
<li><a class="reference internal" href="#opengl" id="id12">開放圖形庫(OpenGL)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#what-platform-specific-gui-toolkits-exist-for-python" id="id13">What platform-specific GUI toolkits exist for Python?</a></li>
<li><a class="reference internal" href="#tkinter-questions" id="id14">Tkinter questions</a><ul>
<li><a class="reference internal" href="#how-do-i-freeze-tkinter-applications" id="id15">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="id16">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="id17">I can’t get key bindings to work in Tkinter: why?</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="general-gui-questions">
<h2><a class="toc-backref" href="#id4">常見圖形化使用者界面(GUI) 問題</a><a class="headerlink" href="#general-gui-questions" title="本標題的永久連結">¶</a></h2>
</div>
<div class="section" id="what-platform-independent-gui-toolkits-exist-for-python">
<h2><a class="toc-backref" href="#id5">What platform-independent GUI toolkits exist for Python?</a><a class="headerlink" href="#what-platform-independent-gui-toolkits-exist-for-python" title="本標題的永久連結">¶</a></h2>
<p>Depending on what platform(s) you are aiming at, there are several. Some
of them haven’t been ported to Python 3 yet. At least <a class="reference internal" href="#tkinter">Tkinter</a> and <a class="reference internal" href="#qt">Qt</a>
are known to be Python 3-compatible.</p>
<div class="section" id="tkinter">
<h3><a class="toc-backref" href="#id6">Tkinter</a><a class="headerlink" href="#tkinter" title="本標題的永久連結">¶</a></h3>
<p>Standard builds of Python include an object-oriented interface to the Tcl/Tk
widget set, called <a class="reference internal" href="../library/tk.html#tkinter"><span class="std std-ref">tkinter</span></a>. This is probably the easiest to
install (since it comes included with most
<a class="reference external" href="https://www.python.org/downloads/">binary distributions</a> of Python) and use.
For more info about Tk, including pointers to the source, see the
<a class="reference external" href="https://www.tcl.tk">Tcl/Tk home page</a>. Tcl/Tk is fully portable to the
Mac OS X, Windows, and Unix platforms.</p>
</div>
<div class="section" id="wxwidgets">
<h3><a class="toc-backref" href="#id7">wxWidgets</a><a class="headerlink" href="#wxwidgets" title="本標題的永久連結">¶</a></h3>
<p>wxWidgets (<a class="reference external" href="https://www.wxwidgets.org">https://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, Mac OS 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><a class="reference external" href="https://www.wxpython.org">wxPython</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="#id8">Qt</a><a class="headerlink" href="#qt" title="本標題的永久連結">¶</a></h3>
<p>There are bindings available for the Qt toolkit (using either <a class="reference external" href="https://riverbankcomputing.com/software/pyqt/intro">PyQt</a> or <a class="reference external" href="https://wiki.qt.io/PySide">PySide</a>) and for KDE (<a class="reference external" href="https://techbase.kde.org/Languages/Python/Using_PyKDE_4">PyKDE4</a>).
PyQt is currently more mature than PySide, but you must buy a PyQt license from
<a class="reference external" href="https://www.riverbankcomputing.com/commercial/license-faq">Riverbank Computing</a>
if you want to write proprietary applications. PySide is free for all applications.</p>
<p>Qt 4.5 upwards is licensed under the LGPL license; also, commercial licenses
are available from <a class="reference external" href="https://www.qt.io/licensing/">The Qt Company</a>.</p>
</div>
<div class="section" id="gtk">
<h3><a class="toc-backref" href="#id9">Gtk+</a><a class="headerlink" href="#gtk" title="本標題的永久連結">¶</a></h3>
<p>The <a class="reference external" href="https://wiki.gnome.org/Projects/PyGObject">GObject introspection bindings</a>
for Python allow you to write GTK+ 3 applications. There is also a
<a class="reference external" href="https://python-gtk-3-tutorial.readthedocs.io">Python GTK+ 3 Tutorial</a>.</p>
<p>The older PyGtk bindings for the <a class="reference external" href="https://www.gtk.org">Gtk+ 2 toolkit</a> have
been implemented by James Henstridge; see <<a class="reference external" href="http://www.pygtk.org">http://www.pygtk.org</a>>.</p>
</div>
<div class="section" id="kivy">
<h3><a class="toc-backref" href="#id10">Kivy</a><a class="headerlink" href="#kivy" title="本標題的永久連結">¶</a></h3>
<p><a class="reference external" href="https://kivy.org/">Kivy</a> is a cross-platform GUI library supporting both
desktop operating systems (Windows, macOS, Linux) and mobile devices (Android,
iOS). It is written in Python and Cython, and can use a range of windowing
backends.</p>
<p>Kivy is free and open source software distributed under the MIT license.</p>
</div>
<div class="section" id="fltk">
<h3><a class="toc-backref" href="#id11">FLTK</a><a class="headerlink" href="#fltk" title="本標題的永久連結">¶</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="opengl">
<h3><a class="toc-backref" href="#id12">開放圖形庫(OpenGL)</a><a class="headerlink" href="#opengl" title="本標題的永久連結">¶</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="#id13">What platform-specific GUI toolkits exist for Python?</a><a class="headerlink" href="#what-platform-specific-gui-toolkits-exist-for-python" title="本標題的永久連結">¶</a></h2>
<p>By installing the <a class="reference external" href="https://pythonhosted.org/pyobjc/">PyObjc Objective-C bridge</a>, Python programs can use Mac OS X’s
Cocoa libraries.</p>
<p><a class="reference internal" href="windows.html#windows-faq"><span class="std std-ref">Pythonwin</span></a> by Mark Hammond includes an interface to the
Microsoft Foundation Classes and a Python programming environment
that’s written mostly in Python using the MFC classes.</p>
</div>
<div class="section" id="tkinter-questions">
<h2><a class="toc-backref" href="#id14">Tkinter questions</a><a class="headerlink" href="#tkinter-questions" title="本標題的永久連結">¶</a></h2>
<div class="section" id="how-do-i-freeze-tkinter-applications">
<h3><a class="toc-backref" href="#id15">How do I freeze Tkinter applications?</a><a class="headerlink" href="#how-do-i-freeze-tkinter-applications" title="本標題的永久連結">¶</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><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TCL_LIBRARY</span></code> and <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TK_LIBRARY</span></code>
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
<code class="xref c c-func docutils literal notranslate"><span class="pre">Tclsam_init()</span></code>, etc. inside Python’s
<code class="file docutils literal notranslate"><span class="pre">Modules/tkappinit.c</span></code>, 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="#id16">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="本標題的永久連結">¶</a></h3>
<p>On platforms other than Windows, 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 <code class="xref c c-func docutils literal notranslate"><span class="pre">XtAddInput()</span></code> 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. See <a class="reference internal" href="../library/tkinter.html#tkinter-file-handlers"><span class="std std-ref">File Handlers</span></a>.</p>
</div>
<div class="section" id="i-can-t-get-key-bindings-to-work-in-tkinter-why">
<h3><a class="toc-backref" href="#id17">I can’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="本標題的永久連結">¶</a></h3>
<p>An often-heard complaint is that event handlers bound to events with the
<code class="xref py py-meth docutils literal notranslate"><span class="pre">bind()</span></code> 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 option).</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目錄</a></h3>
<ul>
<li><a class="reference internal" href="#">圖形化使用者界面常見問答集</a><ul>
<li><a class="reference internal" href="#general-gui-questions">常見圖形化使用者界面(GUI) 問題</a></li>
<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>上個主題</h4>
<p class="topless"><a href="windows.html"
title="上一章">FAQ:在 Windows 使用 Python</a></p>
<h4>下個主題</h4>
<p class="topless"><a href="installed.html"
title="下一章">為什麼Python被安裝在我的機器上?常見問答集</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.7/Doc/faq/gui.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="installed.html" title="為什麼Python被安裝在我的機器上?常見問答集"
>下一頁</a> |</li>
<li class="right" >
<a href="windows.html" title="FAQ:在 Windows 使用 Python"
>上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 常見問題</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" 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>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 2001-2018, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on 8月 22, 2018.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.7.
</div>
</body>
</html>