blob: 2ad5e0ebe3c9cca780a33936fc2259e5bd089583 [file] [log] [blame]
Fred Drake10cd3152001-11-30 18:17:24 +00001\chapter{Graphical User Interfaces with Tk \label{tkinter}}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00002
3\index{GUI}
4\index{Graphical User Interface}
5\index{Tkinter}
6\index{Tk}
7
8Tk/Tcl has long been an integral part of Python. It provides a robust
9and platform independent windowing toolkit, that is available to
10Python programmers using the \refmodule{Tkinter} module, and its
11extension, the \refmodule{Tix} module.
12
Fred Drake666ca802001-11-16 06:02:55 +000013The \refmodule{Tkinter} module is a thin object--oriented layer on top of
Fred Drake7cf4e5b2001-11-15 17:22:04 +000014Tcl/Tk. To use \refmodule{Tkinter}, you don't need to write Tcl code,
15but you will need to consult the Tk documentation, and occasionally
16the Tcl documentation. \refmodule{Tkinter} is a set of wrappers that
17implement the Tk widgets as Python classes. In addition, the internal
18module \module{\_tkinter} provides a threadsafe mechanism which allows
19Python and Tcl to interact.
20
Fred Drake666ca802001-11-16 06:02:55 +000021Tk is not the only GUI for Python, but is however the most commonly
22used one; see section~\ref{other-gui-modules}, ``Other User Interface
23Modules and Packages,'' for more information on other GUI toolkits for
24Python.
Fred Drake7cf4e5b2001-11-15 17:22:04 +000025
26% Other sections I have in mind are
27% Tkinter internals
28% Freezing Tkinter applications
29
30\localmoduletable
31
32
Fred Drakec66ff202001-11-16 01:05:27 +000033\section{\module{Tkinter} ---
34 Python interface to Tcl/Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +000035
36\declaremodule{standard}{Tkinter}
37\modulesynopsis{Interface to Tcl/Tk for graphical user interfaces}
38\moduleauthor{Guido van Rossum}{guido@Python.org}
39
40The \module{Tkinter} module (``Tk interface'') is the standard Python
41interface to the Tk GUI toolkit, now maintained at ActiveState. Both
Fred Drakec37b65e2001-11-28 07:26:15 +000042Tk and \module{Tkinter} are available on most \UNIX{} platforms, as well
Fred Drake7cf4e5b2001-11-15 17:22:04 +000043as on Windows and Macintosh systems.
44
45\begin{seealso}
46\seetitle[http://www.python.org/topics/tkinter/]
47 {Python Tkinter Resources}
48 {The Python Tkinter Topic Guide provides a great
49 deal of information on using Tk from Python and links to
50 other sources of information on Tk.}
51
52\seetitle[http://www.pythonware.com/library/an-introduction-to-tkinter.htm]
53 {An Introduction to Tkinter}
54 {Fredrik Lundh's on-line reference material.}
55
56\seetitle[http://www.nmt.edu/tcc/help/pubs/lang.html]
57 {Tkinter reference: a GUI for Python}
58 {On-line reference material.}
59
60\seetitle[http://jtkinter.sourceforge.net]
61 {Tkinter for JPython}
62 {The Jython interface to Tkinter.}
63
64\seetitle[http://www.amazon.com/exec/obidos/ASIN/1884777813]
65 {Python and Tkinter Programming}
66 {The book by John Grayson (ISBN 1-884777-81-3).}
67\end{seealso}
68
69
70\subsection{Tkinter Modules}
71
Fred Drake666ca802001-11-16 06:02:55 +000072Most of the time, the \refmodule{Tkinter} module is all you really
73need, but a number of additional modules are available as well. The
74Tk interface is located in a binary module named \module{_tkinter}.
75This module contains the low-level interface to Tk, and should never
76be used directly by application programmers. It is usually a shared
77library (or DLL), but might in some cases be statically linked with
78the Python interpreter.
Fred Drake7cf4e5b2001-11-15 17:22:04 +000079
80In addition to the Tk interface module, \refmodule{Tkinter} includes a
81number of Python modules. The two most important modules are the
82\refmodule{Tkinter} module itself, and a module called
83\module{Tkconstants}. The former automatically imports the latter, so
84to use Tkinter, all you need to do is to import one module:
85
86\begin{verbatim}
87import Tkinter
88\end{verbatim}
89
90Or, more often:
91
92\begin{verbatim}
93from Tkinter import *
94\end{verbatim}
95
96\begin{classdesc}{Tk}{screenName=None, baseName=None, className='Tk'}
97The \class{Tk} class is instantiated without arguments.
98This creates a toplevel widget of Tk which usually is the main window
99of an appliation. Each instance has its own associated Tcl interpreter.
100% FIXME: The following keyword arguments are currently recognized:
101\end{classdesc}
102
103Other modules that provide Tk support include:
104
105\begin{description}
106% \declaremodule{standard}{Tkconstants}
107% \modulesynopsis{Constants used by Tkinter}
108% FIXME
109
Fred Drakec66ff202001-11-16 01:05:27 +0000110\item[\module{tkColorChooser}]
111Dialog to let the user choose a color.
112
113\item[\module{tkCommonDialog}]
Fred Drake04677752001-11-30 19:24:49 +0000114Base class for the dialogs defined in the other modules listed here.
Fred Drakec66ff202001-11-16 01:05:27 +0000115
116\item[\module{tkFileDialog}]
117Common dialogs to allow the user to specify a file to open or save.
118
119\item[\module{tkFont}]
120Utilities to help work with fonts.
121
122\item[\module{tkMessageBox}]
123Access to standard Tk dialog boxes.
124
125\item[\module{tkSimpleDialog}]
126Basic dialogs and convenience functions.
127
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000128\item[\module{Tkdnd}]
129Drag-and-drop support for \refmodule{Tkinter}.
130This is experimental and should become deprecated when it is replaced
131with the Tk DND.
132
133\item[\refmodule{turtle}]
134Turtle graphics in a Tk window.
135
136\end{description}
137
138\subsection{Tkinter Life Preserver}
Fred Drakec66ff202001-11-16 01:05:27 +0000139\sectionauthor{Matt Conway}{}
140% Converted to LaTeX by Mike Clarkson.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000141
142This section is not designed to be an exhaustive tutorial on either
143Tk or Tkinter. Rather, it is intended as a stop gap, providing some
144introductory orientation on the system.
145
146Credits:
147\begin{itemize}
148\item Tkinter was written by Steen Lumholt and Guido van Rossum.
149\item Tk was written by John Ousterhout while at Berkeley.
150\item This Life Preserver was written by Matt Conway at
151the University of Virginia.
152\item The html rendering, and some liberal editing, was
153produced from a FrameMaker version by Ken Manheimer.
154\item Fredrik Lundh elaborated and revised the class interface descriptions,
155to get them current with Tk 4.2.
156\item Mike Clarkson converted the documentation to \LaTeX, and compiled the
157User Interface chapter of the reference manual.
158\end{itemize}
159
160
161\subsubsection{How To Use This Section}
162
163This section is designed in two parts: the first half (roughly) covers
164background material, while the second half can be taken to the
165keyboard as a handy reference.
166
167When trying to answer questions of the form ``how do I do blah'', it
168is often best to find out how to do``blah'' in straight Tk, and then
169convert this back into the corresponding \refmodule{Tkinter} call.
170Python programmers can often guess at the correct Python command by
171looking at the Tk documentation. This means that in order to use
172Tkinter, you will have to know a little bit about Tk. This document
173can't fulfill that role, so the best we can do is point you to the
174best documentation that exists. Here are some hints:
175
176\begin{itemize}
177\item The authors strongly suggest getting a copy of the Tk man
178pages. Specifically, the man pages in the \code{mann} directory are most
179useful. The \code{man3} man pages describe the C interface to the Tk
180library and thus are not especially helpful for script writers.
181
182\item Addison-Wesley publishes a book called \citetitle{Tcl and the
183Tk Toolkit} by John Ousterhout (ISBN 0-201-63337-X) which is a good
184introduction to Tcl and Tk for the novice. The book is not
185exhaustive, and for many details it defers to the man pages.
186
187\item \file{Tkinter.py} is a last resort for most, but can be a good
188place to go when nothing else makes sense.
189\end{itemize}
190
191\begin{seealso}
192\seetitle[http://tcl.activestate.com/]
193 {ActiveState Tcl Home Page}
194 {The Tk/Tcl development is largely taking place at
195 ActiveState.}
196\seetitle[http://www.amazon.com/exec/obidos/ASIN/020163337X]
197 {Tcl and the Tk Toolkit}
198 {The book by John Ousterhout, the inventor of Tcl .}
199\seetitle[http://www.amazon.com/exec/obidos/ASIN/0130220280]
200 {Practical Programming in Tcl and Tk}
201 {Brent Welch's encyclopedic book.}
202\end{seealso}
203
204
205\subsubsection{A Simple Hello World Program} % HelloWorld.html
206
207%begin{latexonly}
208%\begin{figure}[hbtp]
209%\centerline{\epsfig{file=HelloWorld.gif,width=.9\textwidth}}
210%\vspace{.5cm}
211%\caption{HelloWorld gadget image}
212%\end{figure}
213%See also the hello-world \ulink{notes}{classes/HelloWorld-notes.html} and
214%\ulink{summary}{classes/HelloWorld-summary.html}.
215%end{latexonly}
216
217
218\begin{verbatim}
219from Tkinter import * 1
220 2
221class Application(Frame): 3
222 def say_hi(self): 4
223 print "hi there, everyone!" 5
224 6
225 def createWidgets(self): 7
226 self.QUIT = Button(self) 8
227 self.QUIT["text"] = "QUIT" 9
228 self.QUIT["fg"] = "red" 10
229 self.QUIT["command"] = self.quit 11
230 12
231 self.QUIT.pack({"side": "left"}) 13
232 14
233 self.hi_there = Button(self) 15
234 self.hi_there["text"] = "Hello", 16
235 self.hi_there["command"] = self.say_hi 17
236 18
237 self.hi_there.pack({"side": "left"}) 19
238 20
239 21
240 def __init__(self, master=None): 22
241 Frame.__init__(self, master) 23
242 self.pack() 24
243 self.createWidgets() 25
244 26
245app = Application() 27
246app.mainloop() 28
247\end{verbatim}
248
249\ifhtml
250\subsection{An Overview of The Tkinter Classes} % TkClassHier.html
251
252%begin{latexonly}
253%\begin{figure}[hbtp]
254%\centerline{\epsfig{file=TkClassHier.gif,width=.9\textwidth}}
255%\caption{Class Hierarchy Image}
256%\end{figure}
257%end{latexonly}
258
259The class hierarchy looks complicated, but in actual practice,
260application programmers almost always refer to the classes at the very
261bottom of the hierarchy.
262
263Here are links to the interfaces for each of the concrete widgets:
264
265\begin{itemize}
266\item \citetitle[classes/ClassButton.html]{Button}
267\item \citetitle[classes/ClassCanvas.html]{Canvas}
268\item \citetitle[classes/ClassCheckbutton.html]{Checkbutton}
269\item \citetitle[classes/ClassEntry.html]{Entry}
270\item \citetitle[classes/ClassFrame.html]{Frame}
271\item \citetitle[classes/ClassLabel.html]{Label}
272\item \citetitle[classes/ClassListbox.html]{Listbox}
273\item \citetitle[classes/ClassMenu.html]{Menu}
274\item \citetitle[classes/ClassMenubutton.html]{Menubutton}
275\item \citetitle[classes/ClassMessage.html]{Message}
276\item \citetitle[classes/ClassMisc.html]{*Misc}
277\item \citetitle[classes/ClassPacker.html]{*Pack}
278\item \citetitle[classes/ClassPlacer.html]{*Place}
279\item \citetitle[classes/ClassRadiobutton.html]{Radiobutton}
280\item \citetitle[classes/ClassScale.html]{Scale}
281\item \citetitle[classes/ClassScrollbar.html]{Scrollbar}
282\item \citetitle[classes/ClassText.html]{Text}
283\item \citetitle[classes/ClassTk.html]{**Tk}
284\item \citetitle[classes/ClassToplevel.html]{Toplevel}
285\item \citetitle[classes/ClassWidget.html]{***Widget}
286\item \citetitle[classes/ClassWm.html]{*Wm}
287\end{itemize}
288
289
290Notes:
291\begin{itemize}
292\item These classes are provided for the purposes of
293organizing certain functions under one namespace. They aren't meant to
294be instantiated independently.
295\item The Tk class is meant to be instantiated only once in
296an application. Application programmers need not instantiate one
297explicitly, the system creates one whenever any of the other classes
298are instantiated.
299\item The Widget class is not meant to be instantiated, it
Fred Drakec66ff202001-11-16 01:05:27 +0000300is meant only for subclassing to make ``real'' widgets. (in \Cpp, this
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000301is called an `abstract class')
302\end{itemize}
303\fi
304
305
306\subsection{A (Very) Quick Look at Tcl/Tk} % BriefTclTk.html
307
308To make use of this reference material, there will be times when you
309will need to know how to read short passages of Tk and how to identify
310the various parts of a Tk command.
Fred Drake666ca802001-11-16 06:02:55 +0000311(See section~\ref{tkinter-basic-mapping} for the
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000312\refmodule{Tkinter} equivalents of what's below.)
313
314Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
315just lists of tokens separated by spaces. A Tk widget is just its
316\emph{class}, the \emph{options} that help configure it, and the
317\emph{actions} that make it do useful things.
318
319To make a widget in Tk, the command is always of the form:
320
321\begin{verbatim}
322 classCommand newPathname options
323\end{verbatim}
324
325\begin{description}
326\item[\var{classCommand}]
327denotes which kind of widget to make (a button, a label, a menu...)
328
329\item[\var{newPathname}]
330is the new name for this widget. All names in Tk must be unique. To
331help enforce this, widgets in Tk are named with \emph{pathnames}, just
332like files in a file system. The top level widget, the \emph{root},
333is called \code{.} (period) and children are delimited by more
334periods. For example, \code{.myApp.controlPanel.okButton} might be
335the name of a widget.
336
337\item[\var{options} ]
338configure the widget's appearance and in some cases, its
339behavior. The options come in the form of a list of flags and values.
340Flags are proceeded by a `-', like unix shell command flags, and
341values are put in quotes if they are more than one word.
342\end{description}
343
344For example:
345
346\begin{verbatim}
347 button .fred -fg red -text "hi there"
348 ^ ^ \_____________________/
349 | | |
350 class new options
351 command widget (-opt val -opt val ...)
352\end{verbatim}
353
354Once created, the pathname to the widget becomes a new command. This
355new \var{widget command} is the programmer's handle for getting the new
356widget to perform some \var{action}. In C, you'd express this as
Fred Drakec66ff202001-11-16 01:05:27 +0000357someAction(fred, someOptions), in \Cpp, you would express this as
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000358fred.someAction(someOptions), and in Tk, you say:
359
360\begin{verbatim}
361 .fred someAction someOptions
362\end{verbatim}
363
364Note that the object name, \code{.fred}, starts with a dot.
365
366As you'd expect, the legal values for \var{someAction} will depend on
367the widget's class: \code{.fred disable} works if fred is a
368button (fred gets greyed out), but does not work if fred is a label
369(disabling of labels is not supported in Tk).
370
371The legal values of \var{someOptions} is action dependent. Some
372actions, like \code{disable}, require no arguments, others, like
373a text-entry box's \code{delete} command, would need arguments
374to specify what range of text to delete.
375
376
377\subsection{Mapping Basic Tk into Tkinter
378 \label{tkinter-basic-mapping}}
379
380Class commands in Tk correspond to class constructors in Tkinter.
381
382\begin{verbatim}
383 button .fred =====> fred = Button()
384\end{verbatim}
385
386The master of an object is implicit in the new name given to it at
387creation time. In Tkinter, masters are specified explicitly.
388
389\begin{verbatim}
390 button .panel.fred =====> fred = Button(panel)
391\end{verbatim}
392
393The configuration options in Tk are given in lists of hyphened tags
394followed by values. In Tkinter, options are specified as
395keyword-arguments in the instance constructor, and keyword-args for
396configure calls or as instance indices, in dictionary style, for
Fred Drake666ca802001-11-16 06:02:55 +0000397established instances. See section~\ref{tkinter-setting-options} on
398setting options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000399
400\begin{verbatim}
401 button .fred -fg red =====> fred = Button(panel, fg = "red")
402 .fred configure -fg red =====> fred["fg"] = red
403 OR ==> fred.config(fg = "red")
404\end{verbatim}
405
406In Tk, to perform an action on a widget, use the widget name as a
407command, and follow it with an action name, possibly with arguments
408(options). In Tkinter, you call methods on the class instance to
409invoke actions on the widget. The actions (methods) that a given
410widget can perform are listed in the Tkinter.py module.
411
412\begin{verbatim}
413 .fred invoke =====> fred.invoke()
414\end{verbatim}
415
416To give a widget to the packer (geometry manager), you call pack with
417optional arguments. In Tkinter, the Pack class holds all this
418functionality, and the various forms of the pack command are
419implemented as methods. All widgets in \refmodule{Tkinter} are
420subclassed from the Packer, and so inherit all the packing
421methods. See the \refmodule{Tix} module documentation for additional
422information on the Form geometry manager.
423
424\begin{verbatim}
425 pack .fred -side left =====> fred.pack(side = "left")
426\end{verbatim}
427
428
429\subsection{How Tk and Tkinter are Related} % Relationship.html
430
Fred Drake666ca802001-11-16 06:02:55 +0000431\note{This was derived from a graphical image; the image will be used
432 more directly in a subsequent version of this document.}
433
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000434From the top down:
435\begin{description}
436\item[\b{Your App Here (Python)}]
437A Python application makes a \refmodule{Tkinter} call.
438
439\item[\b{Tkinter (Python Module)}]
440This call (say, for example, creating a button widget), is
441implemented in the \emph{Tkinter} module, which is written in
442Python. This Python function will parse the commands and the
443arguments and convert them into a form that makes them look as if they
444had come from a Tk script instead of a Python script.
445
446\item[\b{tkinter (C)}]
447These commands and their arguments will be passed to a C function
448in the \emph{tkinter} - note the lowercase - extension module.
449
450\item[\b{Tk Widgets} (C and Tcl)]
451This C function is able to make calls into other C modules,
452including the C functions that make up the Tk library. Tk is
453implemented in C and some Tcl. The Tcl part of the Tk widgets is used
454to bind certain default behaviors to widgets, and is executed once at
455the point where the Python \refmodule{Tkinter} module is
456imported. (The user never sees this stage).
457
458\item[\b{Tk (C)}]
459The Tk part of the Tk Widgets implement the final mapping to ...
460
461\item[\b{Xlib (C)}]
462the Xlib library to draw graphics on the screen.
463\end{description}
464
465
466\subsection{Handy Reference}
467
468\subsubsection{Setting Options
469 \label{tkinter-setting-options}}
470
471Options control things like the color and border width of a widget.
472Options can be set in three ways:
473
474\begin{description}
475\item[At object creation time, using keyword arguments]:
476\begin{verbatim}
477fred = Button(self, fg = "red", bg = "blue")
478\end{verbatim}
479\item[After object creation, treating the option name like a dictionary index]:
480\begin{verbatim}
481fred["fg"] = "red"
482fred["bg"] = "blue"
483\end{verbatim}
484\item[Use the config() method to update multiple attrs subesequent to
485object creation]:
486\begin{verbatim}
487fred.config(fg = "red", bg = "blue")
488\end{verbatim}
489\end{description}
490
491For a complete explanation of a given option and its behavior, see the
492Tk man pages for the widget in question.
493
494Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
495OPTIONS" for each widget. The former is a list of options that are
496common to many widgets, the latter are the options that are
497ideosyncratic to that particular widget. The Standard Options are
498documented on the \manpage{options}{3} man page.
499
500No distinction between standard and widget-specific options is made in
501this document. Some options don't apply to some kinds of widgets.
502Whether a given widget responds to a particular option depends on the
503class of the widget; buttons have a \code{command} option, labels do not.
504
505The options supported by a given widget are listed in that widget's
506man page, or can be queried at runtime by calling the
507\kbd{config()} method with arguments, or by calling the keys()
508method on that widget. The return value of these calls is a dictionary
509whose key is the name of the option (e.g. \kbd{relief}) and whose
510values are 5 tuples.
511
512(Some options, like \kbd{bg} are synonyms for common options with
513hard-to-type names (\kbd{bg} is shorthand for "background").
514Passing the \kbd{config()} method the name of a
515shorthand option will return a 2-tuple, not 5-tuple. The 2-tuple
516passed back will contain the name of the synonym ``real''
517option. (\kbd{bg}, \kbd{background}))
518
519\begin{tableiii}{c|l|l}{textrm}{Index}{Meaning}{Example}
520 \lineiii{0}{option name} {\code{'relief'}}
521 \lineiii{1}{option name for database lookup} {\code{'relief'}}
522 \lineiii{2}{option class for database lookup} {\code{'Relief'}}
523 \lineiii{3}{default value} {\code{'raised'}}
524 \lineiii{4}{current value} {\code{'groove'}}
525\end{tableiii}
526
527
528Example:
529
530\begin{verbatim}
531>>> print fred.config()
532{'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}
533\end{verbatim}
534
535Of course, the dictionary printed will include all the options
536available and their values. This is meant only as an example.
537
538
539\subsubsection{The Packer} % Packer.html
540\index{packing (widgets)}
541
542The packer is one of Tk's geometry-management mechanisms. See also
543\citetitle[classes/ClassPacker.html]{the Packer class interface}.
544
545Geometry managers are used to specify the relative positioning of the
546positioning of widgets within their container - their mutual
547\emph{master}. In contrast to the more cumbersome \emph{placer}
548(which is used less commonly, and we do not cover here), the packer
549takes qualitative relationship specification - \emph{above}, \emph{to
550the left of}, \emph{filling}, etc - and works everything out to
551determine the exact placement coordinates for you.
552
553The size of any \emph{master} widget is determined by the size of
554the "slave widgets" inside. The packer is used to control where slave
555widgets appear inside the master into which they are packed. You can
556pack widgets into frames, and frames into other frames, in order to
557achieve the kind of layout you desire. Additionally, the arrangement
558is dynamically adjusted to accomodate incremental changes to the
559configuration, once it is packed.
560
561Note that widgets do not appear until they have had their geometry
562specified with a geometry manager. It's a common early mistake to
563leave out the geometry specification, and then be surprised when the
564widget is created but nothing appears. A widget will appear only
565after it has had, for example, the packer's \method{pack()} method
566applied to it.
567
568The pack() method can be called with keyword-option/value pairs that
569control where the widget is to appear within its container, and how it
570is to behave when the main application window is resized. Here are
571some examples:
572
573\begin{verbatim}
574 fred.pack() # defaults to side = "top"
575 fred.pack(side = "left")
576 fred.pack(expand = 1)
577\end{verbatim}
578
579
580\subsubsection{Packer Options}
581
582For more extensive information on the packer and the options that it
583can take, see the man pages and page 183 of John Ousterhout's book.
584
585\begin{description}
586\item[\b{anchor }]
587Anchor type. Denotes where the packer is to place each slave in its
588parcel.
589
590\item[\b{expand}]
591Boolean, \code{0} or \code{1}.
592
593\item[\b{fill}]
594Legal values: \code{'x'}, \code{'y'}, \code{'both'}, \code{'none'}.
595
596\item[\b{ipadx} and \b{ipady}]
597A distance - designating internal padding on each side of the slave
598widget.
599
600\item[\b{padx} and \b{pady}]
601A distance - designating external padding on each side of the slave
602widget.
603
604\item[\b{side}]
605Legal values are: \code{'left'}, \code{'right'}, \code{'top'},
606\code{'bottom'}.
607\end{description}
608
609
610\subsubsection{Coupling Widget Variables} % VarCouplings.html
611
612The current-value setting of some widgets (like text entry widgets)
613can be connected directly to application variables by using special
614options. These options are \code{variable}, \code{textvariable},
615\code{onvalue}, \code{offvalue}, and \code{value}. This
616connection works both ways: if the variable changes for any reason,
617the widget it's connected to will be updated to reflect the new value.
618
619Unfortunately, in the current implementation of \refmodule{Tkinter} it is
620not possible to hand over an arbitrary Python variable to a widget
621through a \code{variable} or \code{textvariable} option. The only
622kinds of variables for which this works are variables that are
623subclassed from a class called Variable, defined in the
624\refmodule{Tkinter} module.
625
626There are many useful subclasses of Variable already defined:
627\class{StringVar}, \class{IntVar}, \class{DoubleVar}, and
628\class{BooleanVar}. To read the current value of such a variable,
629call the \method{get()} method on
630it, and to change its value you call the \method{set()} method. If
631you follow this protocol, the widget will always track the value of
632the variable, with no further intervention on your part.
633
634For example:
635\begin{verbatim}
636class App(Frame):
637 def __init__(self, master=None):
638 Frame.__init__(self, master)
639 self.pack()
640
641 self.entrythingy = Entry()
642 self.entrythingy.pack()
643
644 self.button.pack()
645 # here is the application variable
646 self.contents = StringVar()
647 # set it to some value
648 self.contents.set("this is a variable")
649 # tell the entry widget to watch this variable
650 self.entrythingy["textvariable"] = self.contents
651
652 # and here we get a callback when the user hits return.
653 # we will have the program print out the value of the
654 # application variable when the user hits return
655 self.entrythingy.bind('<Key-Return>',
656 self.print_contents)
657
658 def print_contents(self, event):
659 print "hi. contents of entry is now ---->", \
660 self.contents.get()
661\end{verbatim}
662
663
664\subsubsection{The Window Manager} % WindowMgr.html
665\index{window manager (widgets)}
666
667In Tk, there is a utility command, \code{wm}, for interacting with the
668window manager. Options to the \code{wm} command allow you to control
669things like titles, placement, icon bitmaps, and the like. In
670\refmodule{Tkinter}, these commands have been implemented as methods
671on the \class{Wm} class. Toplevel widgets are subclassed from the
672\class{Wm} class, and so can call the \class{Wm} methods directly.
673
674%See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
675
676To get at the toplevel window that contains a given widget, you can
677often just refer to the widget's master. Of course if the widget has
678been packed inside of a frame, the master won't represent a toplevel
679window. To get at the toplevel window that contains an arbitrary
680widget, you can call the \method{_root()} method. This
681method begins with an underscore to denote the fact that this function
682is part of the implementation, and not an interface to Tk functionality.
683
684Here are some examples of typical usage:
685
686\begin{verbatim}
687import Tkinter
688class App(Frame):
689 def __init__(self, master=None):
690 Frame.__init__(self, master)
691 self.pack()
692
693
694# create the application
695myapp = App()
696
697#
698# here are method calls to the window manager class
699#
700myapp.master.title("My Do-Nothing Application")
701myapp.master.maxsize(1000, 400)
702
703# start the program
704myapp.mainloop()
705\end{verbatim}
706
707
708\subsubsection{Tk Option Data Types} % OptionTypes.html
709
710\index{Tk Option Data Types}
711
712\begin{description}
713\item[anchor]
714Legal values are points of the compass: \code{"n"},
715\code{"ne"}, \code{"e"}, \code{"se"}, \code{"s"},
716\code{"sw"}, \code{"w"}, \code{"nw"}, and also
717\code{"center"}.
718
719\item[bitmap]
720There are eight built-in, named bitmaps: \code{'error'}, \code{'gray25'},
721\code{'gray50'}, \code{'hourglass'}, \code{'info'}, \code{'questhead'},
722\code{'question'}, \code{'warning'}. To specify an X bitmap
723filename, give the full path to the file, preceded with an \code{@},
724as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
725
726\item[boolean]
727You can pass integers 0 or 1 or the stings \code{"yes"} or \code{"no"} .
728
729\item[callback]
730This is any Python function that takes no arguments. For example:
731\begin{verbatim}
732 def print_it():
733 print "hi there"
734 fred["command"] = print_it
735\end{verbatim}
736
737\item[color]
738Colors can be given as the names of X colors in the rgb.txt file,
739or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
740bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
741\code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
742legal hex digit. See page 160 of Ousterhout's book for details.
743
744\item[cursor]
745The standard X cursor names from \file{cursorfont.h} can be used,
746without the \code{XC_} prefix. For example to get a hand cursor
747(\constant{XC_hand2}), use the string \code{"hand2"}. You can also
748specify a bitmap and mask file of your own. See page 179 of
749Ousterhout's book.
750
751\item[distance]
752Screen distances can be specified in either pixels or absolute
753distances. Pixels are given as numbers and absolute distances as
754strings, with the trailing character denoting units: \code{c}
755for centimeters, \code{i} for inches, \code{m} for millimeters,
756\code{p} for printer's points. For example, 3.5 inches is expressed
757as \code{"3.5i"}.
758
759\item[font]
760Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
761Font sizes with positive numbers are measured in points;
762sizes with negative numbers are measured in pixels.
763
764\item[geometry]
765This is a string of the form \samp{\var{width}x\var{height}}, where
766width and height are measured in pixels for most widgets (in
767characters for widgets displaying text). For example:
768\code{fred["geometry"] = "200x100"}.
769
770\item[justify]
771Legal values are the strings: \code{"left"},
772\code{"center"}, \code{"right"}, and \code{"fill"}.
773
774\item[region]
775This is a string with four space-delimited elements, each of
776which is a legal distance (see above). For example: \code{"2 3 4
7775"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
778are all legal regions.
779
780\item[relief]
781Determines what the border style of a widget will be. Legal
782values are: \code{"raised"}, \code{"sunken"},
783\code{"flat"}, \code{"groove"}, and \code{"ridge"}.
784
785\item[scrollcommand]
786This is almost always the \method{set()} method of some scrollbar
787widget, but can be any widget method that takes a single argument.
788Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
789in the Python source distribution for an example.
790
791\item[wrap:]
792Must be one of: \code{"none"}, \code{"char"}, or \code{"word"}.
793\end{description}
794
795
796\subsubsection{Bindings and Events} % Bindings.html
797
798\index{bind (widgets)}
799\index{events (widgets)}
800
801The bind method from the widget command allows you to watch for
802certain events and to have a callback function trigger when that event
803type occurs. The form of the bind method is:
804
805\begin{verbatim}
806 def bind(self, sequence, func, add=''):
807\end{verbatim}
808where:
809
810\begin{description}
811\item[sequence]
812is a string that denotes the target kind of event. (See the bind
813man page and page 201 of John Ousterhout's book for details).
814
815\item[func]
816is a Python function, taking one argument, to be invoked when the
817event occurs. An Event instance will be passed as the argument.
818(Functions deployed this way are commonly known as \var{callbacks}.)
819
820\item[add]
821is optional, either \samp{} or \samp{+}. Passing an empty string
822denotes that this binding is to replace any other bindings that this
823event is associated with. Preceeding with a \samp{+} means that this
824function is to be added to the list of functions bound to this event type.
825\end{description}
826
827For example:
828\begin{verbatim}
829 def turnRed(self, event):
830 event.widget["activeforeground"] = "red"
831
832 self.button.bind("<Enter>", self.turnRed)
833\end{verbatim}
834
835Notice how the widget field of the event is being accesed in the
836\method{turnRed()} callback. This field contains the widget that
837caught the X event. The following table lists the other event fields
838you can access, and how they are denoted in Tk, which can be useful
839when referring to the Tk man pages.
840
841\begin{verbatim}
842Tk Tkinter Event Field Tk Tkinter Event Field
843-- ------------------- -- -------------------
844%f focus %A char
845%h height %E send_event
846%k keycode %K keysym
847%s state %N keysym_num
848%t time %T type
849%w width %W widget
850%x x %X x_root
851%y y %Y y_root
852\end{verbatim}
853
854
855\subsubsection{The index Parameter} % Index.html
856
857A number of widgets require``index'' parameters to be passed. These
858are used to point at a specific place in a Text widget, or to
859particular characters in an Entry widget, or to particular menu items
860in a Menu widget.
861
862\begin{description}
863\item[\b{Entry widget indexes (index, view index, etc.)}]
864Entry widgets have options that refer to character positions in the
865text being displayed. You can use these \refmodule{Tkinter} functions
866to access these special points in text widgets:
Fred Drake666ca802001-11-16 06:02:55 +0000867
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000868\begin{description}
869\item[AtEnd()]
870refers to the last position in the text
Fred Drake666ca802001-11-16 06:02:55 +0000871
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000872\item[AtInsert()]
873refers to the point where the text cursor is
Fred Drake666ca802001-11-16 06:02:55 +0000874
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000875\item[AtSelFirst()]
876indicates the beginning point of the selected text
Fred Drake666ca802001-11-16 06:02:55 +0000877
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000878\item[AtSelLast()]
879denotes the last point of the selected text and finally
Fred Drake666ca802001-11-16 06:02:55 +0000880
881\item[At(x\optional{, y})]
882refers to the character at pixel location \var{x}, \var{y} (with
883\var{y} not used in the case of a text entry widget, which contains a
884single line of text).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000885\end{description}
886
887\item[\b{Text widget indexes}]
888The index notation for Text widgets is very rich and is best described
889in the Tk man pages.
890
891\item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
892
893Some options and methods for menus manipulate specific menu entries.
894Anytime a menu index is needed for an option or a parameter, you may
895pass in:
896\begin{itemize}
897\item an integer which refers to the numeric position of the entry in
898the widget, counted from the top, starting with 0;
899\item the string \code{'active'}, which refers to the menu position that is
900currently under the cursor;
901\item the string \code{"last"} which refers to the last menu
902item;
903\item An integer preceded by \code{@}, as in \code{@6}, where the integer is
904interpreted as a y pixel coordinate in the menu's coordinate system;
905\item the string \code{"none"}, which indicates no menu entry at all, most
906often used with menu.activate() to deactivate all entries, and
907finally,
908\item a text string that is pattern matched against the label of the
909menu entry, as scanned from the top of the menu to the bottom. Note
910that this index type is considered after all the others, which means
911that matches for menu items labelled \code{last}, \code{active}, or
912\code{none} may be interpreted as the above literals, instead.
913\end{itemize}
914\end{description}
915
916
Fred Drakec66ff202001-11-16 01:05:27 +0000917\section{\module{Tix} ---
918 Extension widgets for Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000919
920\declaremodule{standard}{Tix}
921\modulesynopsis{Tk Extension Widgets for Tkinter}
922\sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
923
Fred Drakec66ff202001-11-16 01:05:27 +0000924\index{Tix}
925
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000926The \module{Tix} (Tk Interface Extension) module provides an
927additional rich set of widgets. Although the standard Tk library has
928many useful widgets, they are far from complete. The \module{Tix}
929library provides most of the commonly needed widgets that are missing
930from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
931(a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
932also includes many more widgets that are generally useful in a wide
933range of applications: \class{NoteBook}, \class{FileEntry},
934\class{PanedWindow}, etc; there are more than 40 of them.
935
936With all these new widgets, you can introduce new interaction
937techniques into applications, creating more useful and more intuitive
938user interfaces. You can design your application by choosing the most
939appropriate widgets to match the special needs of your application and
940users.
941
942\begin{seealso}
943\seetitle[http://tix.sourceforge.net/]
944 {Tix Homepage}
945 {See the home page for \module{Tix}.}
946\seetitle[http://tix.sourceforge.net/dist/current/man/]
947 {Tix Man Pages}
948 {On-line version of the man pages and reference material.}
949\seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html]
950 {Tix Programming Guide}
951 {On-line version of the programmer's reference material.}
952\seetitle[http://tix.sourceforge.net/Tide/]
953 {Tix Development Applications}
954 {Tix applications for development of Tix and Tkinter programs.
955 Tide applications work under Tk or Tkinter, and include
956 \program{TixInspect}, an inspector to remotely modify and
957 debug Tix/Tk/Tkinter applications.}
958\end{seealso}
959
960
961\subsection{Using Tix}
962
Fred Drake666ca802001-11-16 06:02:55 +0000963\begin{classdesc}{Tix}{screenName\optional{, baseName\optional{, className}}}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000964 Toplevel widget of Tix which represents mostly the main window
965 of an application. It has an associated Tcl interpreter.
966
Fred Drake666ca802001-11-16 06:02:55 +0000967Classes in the \refmodule{Tix} module subclasses the classes in the
968\refmodule{Tkinter} module. The former imports the latter, so to use
969\refmodule{Tix} with Tkinter, all you need to do is to import one
970module. In general, you can just import \refmodule{Tix}, and replace
971the toplevel call to \class{Tkinter.Tk} with \class{Tix.Tk}:
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000972\begin{verbatim}
973import Tix
974from Tkconstants import *
975root = Tix.Tk()
976\end{verbatim}
977\end{classdesc}
978
979To use \refmodule{Tix}, you must have the \refmodule{Tix} widgets installed,
980usually alongside your installation of the Tk widgets.
981To test your installation, try the following:
982\begin{verbatim}
983import Tix
984root = Tix.Tk()
985root.tk.eval('package require Tix')
986\end{verbatim}
987
988If this fails, you have a Tk installation problem which must be
989resolved before proceeding. Use the environment variable \envvar{TIX_LIBRARY}
990to point to the installed \refmodule{Tix} library directory, and
991make sure you have the dynamic object library (\file{tix8183.dll} or
992\file{libtix8183.so}) in the same directory that contains your Tk
993dynamic object library (\file{tk8183.dll} or \file{libtk8183.so}). The
994directory with the dynamic object library should also have a file
995called \file{pkgIndex.tcl} (case sensitive), which contains the line:
996
997\begin{verbatim}
998package ifneeded Tix 8.1 [list load "[file join $dir tix8183.dll]" Tix]
999\end{verbatim} % $ <-- bow to font-lock
1000
1001
1002\subsection{Tix Widgets}
1003
1004\ulink{Tix}
1005{http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm}
1006introduces over 40 widget classes to the \refmodule{Tkinter}
1007repertoire. There is a demo of all the \refmodule{Tix} widgets in the
1008\file{Demo/tix} directory of the standard distribution.
1009
1010
1011% The Python sample code is still being added to Python, hence commented out
1012
1013
1014\subsubsection{Basic Widgets}
1015
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001016\begin{classdesc}{Balloon}{}
1017A \ulink{Balloon}
Fred Drakec66ff202001-11-16 01:05:27 +00001018{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm}
1019that pops up over a widget to provide help. When the user moves the
1020cursor inside a widget to which a Balloon widget has been bound, a
1021small pop-up window with a descriptive message will be shown on the
1022screen.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001023\end{classdesc}
1024
Fred Drakec66ff202001-11-16 01:05:27 +00001025% Python Demo of:
1026% \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001027
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001028\begin{classdesc}{ButtonBox}{}
1029The \ulink{ButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001030{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm}
1031widget creates a box of buttons, such as is commonly used for \code{Ok
1032Cancel}.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001033\end{classdesc}
1034
Fred Drakec66ff202001-11-16 01:05:27 +00001035% Python Demo of:
1036% \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001037
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001038\begin{classdesc}{ComboBox}{}
1039The \ulink{ComboBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001040{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm}
1041widget is similar to the combo box control in MS Windows. The user can
1042select a choice by either typing in the entry subwdget or selecting
1043from the listbox subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001044\end{classdesc}
1045
Fred Drakec66ff202001-11-16 01:05:27 +00001046% Python Demo of:
1047% \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001048
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001049\begin{classdesc}{Control}{}
1050The \ulink{Control}
Fred Drakec66ff202001-11-16 01:05:27 +00001051{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm}
1052widget is also known as the \class{SpinBox} widget. The user can
1053adjust the value by pressing the two arrow buttons or by entering the
1054value directly into the entry. The new value will be checked against
1055the user-defined upper and lower limits.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001056\end{classdesc}
1057
Fred Drakec66ff202001-11-16 01:05:27 +00001058% Python Demo of:
1059% \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001060
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001061\begin{classdesc}{LabelEntry}{}
1062The \ulink{LabelEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001063{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm}
1064widget packages an entry widget and a label into one mega widget. It
1065can be used be used to simplify the creation of ``entry-form'' type of
1066interface.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001067\end{classdesc}
1068
1069% Python Demo of:
1070% \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
1071
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001072\begin{classdesc}{LabelFrame}{}
1073The \ulink{LabelFrame}
Fred Drakec66ff202001-11-16 01:05:27 +00001074{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm}
1075widget packages a frame widget and a label into one mega widget. To
1076create widgets inside a LabelFrame widget, one creates the new widgets
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001077relative to the \member{frame} subwidget and manage them inside the
1078\member{frame} subwidget.
1079\end{classdesc}
1080
1081% Python Demo of:
1082% \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
1083
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001084\begin{classdesc}{Meter}{}
1085The \ulink{Meter}
Fred Drakec66ff202001-11-16 01:05:27 +00001086{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm}
1087widget can be used to show the progress of a background job which may
1088take a long time to execute.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001089\end{classdesc}
1090
1091% Python Demo of:
1092% \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
1093
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001094\begin{classdesc}{OptionMenu}{}
1095The \ulink{OptionMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001096{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm}
1097creates a menu button of options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001098\end{classdesc}
1099
Fred Drakec66ff202001-11-16 01:05:27 +00001100% Python Demo of:
1101% \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001102
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001103\begin{classdesc}{PopupMenu}{}
1104The \ulink{PopupMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001105{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm}
1106widget can be used as a replacement of the \code{tk_popup}
1107command. The advantage of the \refmodule{Tix} \class{PopupMenu} widget
1108is it requires less application code to manipulate.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001109\end{classdesc}
1110
Fred Drakec66ff202001-11-16 01:05:27 +00001111% Python Demo of:
1112% \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001113
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001114\begin{classdesc}{Select}{}
1115The \ulink{Select}
Fred Drakec66ff202001-11-16 01:05:27 +00001116{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm}
1117widget is a container of button subwidgets. It can be used to provide
1118radio-box or check-box style of selection options for the user.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001119\end{classdesc}
1120
Fred Drakec66ff202001-11-16 01:05:27 +00001121% Python Demo of:
1122% \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001123
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001124\begin{classdesc}{StdButtonBox}{}
1125The \ulink{StdButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001126{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm}
1127widget is a group of standard buttons for Motif-like dialog boxes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001128\end{classdesc}
1129
Fred Drakec66ff202001-11-16 01:05:27 +00001130% Python Demo of:
1131% \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001132
1133
1134\subsubsection{File Selectors}
1135
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001136\begin{classdesc}{DirList}{}
1137The \ulink{DirList}
1138{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm} widget
1139displays a list view of a directory, its previous directories and its
1140sub-directories. The user can choose one of the directories displayed
1141in the list or change to another directory.
1142\end{classdesc}
1143
Fred Drakec66ff202001-11-16 01:05:27 +00001144% Python Demo of:
1145% \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001146
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001147\begin{classdesc}{DirTree}{}
1148The \ulink{DirTree}
Fred Drakec66ff202001-11-16 01:05:27 +00001149{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm}
1150widget displays a tree view of a directory, its previous directories
1151and its sub-directories. The user can choose one of the directories
1152displayed in the list or change to another directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001153\end{classdesc}
1154
Fred Drakec66ff202001-11-16 01:05:27 +00001155% Python Demo of:
1156% \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001157
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001158\begin{classdesc}{DirSelectDialog}{}
1159The \ulink{DirSelectDialog}
Fred Drakec66ff202001-11-16 01:05:27 +00001160{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm}
1161widget presents the directories in the file system in a dialog
1162window. The user can use this dialog window to navigate through the
1163file system to select the desired directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001164\end{classdesc}
1165
Fred Drakec66ff202001-11-16 01:05:27 +00001166% Python Demo of:
1167% \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001168
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001169\begin{classdesc}{DirSelectBox}{}
1170The \class{DirSelectBox} is similar
1171to the standard Motif(TM) directory-selection box. It is generally used for
1172the user to choose a directory. DirSelectBox stores the directories mostly
1173recently selected into a ComboBox widget so that they can be quickly
1174selected again.
1175\end{classdesc}
1176
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001177\begin{classdesc}{ExFileSelectBox}{}
1178The \ulink{ExFileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001179{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm}
1180widget is usually embedded in a tixExFileSelectDialog widget. It
1181provides an convenient method for the user to select files. The style
1182of the \class{ExFileSelectBox} widget is very similar to the standard
1183file dialog on MS Windows 3.1.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001184\end{classdesc}
1185
Fred Drakec66ff202001-11-16 01:05:27 +00001186% Python Demo of:
1187%\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001188
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001189\begin{classdesc}{FileSelectBox}{}
1190The \ulink{FileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001191{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm}
1192is similar to the standard Motif(TM) file-selection box. It is
1193generally used for the user to choose a file. FileSelectBox stores the
1194files mostly recently selected into a \class{ComboBox} widget so that
1195they can be quickly selected again.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001196\end{classdesc}
1197
Fred Drakec66ff202001-11-16 01:05:27 +00001198% Python Demo of:
1199% \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001200
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001201\begin{classdesc}{FileEntry}{}
1202The \ulink{FileEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001203{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm}
1204widget can be used to input a filename. The user can type in the
1205filename manually. Alternatively, the user can press the button widget
1206that sits next to the entry, which will bring up a file selection
1207dialog.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001208\end{classdesc}
1209
Fred Drakec66ff202001-11-16 01:05:27 +00001210% Python Demo of:
1211% \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001212
1213
1214\subsubsection{Hierachical ListBox}
1215
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001216\begin{classdesc}{HList}{}
1217The \ulink{HList}
Fred Drakec66ff202001-11-16 01:05:27 +00001218{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm}
1219widget can be used to display any data that have a hierarchical
1220structure, for example, file system directory trees. The list entries
1221are indented and connected by branch lines according to their places
1222in the hierachy.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001223\end{classdesc}
1224
Fred Drakec66ff202001-11-16 01:05:27 +00001225% Python Demo of:
1226% \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001227
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001228\begin{classdesc}{CheckList}{}
1229The \ulink{CheckList}
Fred Drakec66ff202001-11-16 01:05:27 +00001230{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm}
1231widget displays a list of items to be selected by the user. CheckList
1232acts similarly to the Tk checkbutton or radiobutton widgets, except it
1233is capable of handling many more items than checkbuttons or
1234radiobuttons.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001235\end{classdesc}
1236
Fred Drakec66ff202001-11-16 01:05:27 +00001237% Python Demo of:
1238% \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
1239% Python Demo of:
1240% \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
1241% Python Demo of:
1242% \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001243
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001244\begin{classdesc}{Tree}{}
1245The \ulink{Tree}
Fred Drakec66ff202001-11-16 01:05:27 +00001246{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm}
1247widget can be used to display hierachical data in a tree form. The
1248user can adjust the view of the tree by opening or closing parts of
1249the tree.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001250\end{classdesc}
1251
Fred Drakec66ff202001-11-16 01:05:27 +00001252% Python Demo of:
1253% \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001254
Fred Drakec66ff202001-11-16 01:05:27 +00001255% Python Demo of:
1256% \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001257
1258
1259\subsubsection{Tabular ListBox}
1260
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001261\begin{classdesc}{TList}{}
1262The \ulink{TList}
Fred Drakec66ff202001-11-16 01:05:27 +00001263{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm}
1264widget can be used to display data in a tabular format. The list
1265entries of a \class{TList} widget are similar to the entries in the Tk
1266listbox widget. The main differences are (1) the \class{TList} widget
1267can display the list entries in a two dimensional format and (2) you
1268can use graphical images as well as multiple colors and fonts for the
1269list entries.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001270\end{classdesc}
1271
Fred Drakec66ff202001-11-16 01:05:27 +00001272% Python Demo of:
1273% \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
1274% Python Demo of:
1275% \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001276
1277% Grid has yet to be added to Python
1278% \subsubsection{Grid Widget}
Fred Drakec66ff202001-11-16 01:05:27 +00001279% Python Demo of:
1280% \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
1281% Python Demo of:
1282% \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
1283% Python Demo of:
1284% \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001285
1286
1287\subsubsection{Manager Widgets}
1288
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001289\begin{classdesc}{PanedWindow}{}
1290The \ulink{PanedWindow}
Fred Drakec66ff202001-11-16 01:05:27 +00001291{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm}
1292widget allows the user to interactively manipulate the sizes of
1293several panes. The panes can be arranged either vertically or
1294horizontally. The user changes the sizes of the panes by dragging the
1295resize handle between two panes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001296\end{classdesc}
1297
Fred Drakec66ff202001-11-16 01:05:27 +00001298% Python Demo of:
1299% \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001300
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001301\begin{classdesc}{ListNoteBook}{}
1302The \ulink{ListNoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001303{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm}
1304widget is very similar to the \class{TixNoteBook} widget: it can be
1305used to display many windows in a limited space using a notebook
1306metaphor. The notebook is divided into a stack of pages (windows). At
1307one time only one of these pages can be shown. The user can navigate
1308through these pages by choosing the name of the desired page in the
1309\member{hlist} subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001310\end{classdesc}
1311
Fred Drakec66ff202001-11-16 01:05:27 +00001312% Python Demo of:
1313% \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001314
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001315\begin{classdesc}{NoteBook}{}
1316The \ulink{NoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001317{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm}
1318widget can be used to display many windows in a limited space using a
1319notebook metaphor. The notebook is divided into a stack of pages. At
1320one time only one of these pages can be shown. The user can navigate
1321through these pages by choosing the visual ``tabs'' at the top of the
1322NoteBook widget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001323\end{classdesc}
1324
Fred Drakec66ff202001-11-16 01:05:27 +00001325% Python Demo of:
1326% \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001327
1328
1329% \subsubsection{Scrolled Widgets}
Fred Drakec66ff202001-11-16 01:05:27 +00001330% Python Demo of:
1331% \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
1332% Python Demo of:
1333% \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
1334% Python Demo of:
1335% \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
1336% Python Demo of:
1337% \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001338
1339
1340\subsubsection{Image Types}
1341
1342The \refmodule{Tix} module adds:
1343\begin{itemize}
1344\item
1345\ulink{pixmap}
Fred Drake666ca802001-11-16 06:02:55 +00001346{http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm}
1347capabilities to all \refmodule{Tix} and \refmodule{Tkinter} widgets to
1348create color images from XPM files.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001349
1350% Python Demo of: \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
1351
1352% Python Demo of: \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
1353
1354\item
1355\ulink{Compound}
Fred Drake666ca802001-11-16 06:02:55 +00001356{http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html}
1357image types can be used to create images that consists of multiple
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001358horizontal lines; each line is composed of a series of items (texts,
1359bitmaps, images or spaces) arranged from left to right. For example, a
1360compound image can be used to display a bitmap and a text string
1361simutaneously in a Tk \class{Button} widget.
1362
Fred Drake666ca802001-11-16 06:02:55 +00001363% Python Demo of:
1364% \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001365
Fred Drake666ca802001-11-16 06:02:55 +00001366% Python Demo of:
1367% \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001368
Fred Drake666ca802001-11-16 06:02:55 +00001369% Python Demo of:
1370% \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001371
Fred Drake666ca802001-11-16 06:02:55 +00001372% Python Demo of:
1373% \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001374\end{itemize}
1375
1376
1377\subsubsection{Miscellaneous Widgets}
1378
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001379\begin{classdesc}{InputOnly}{}
1380The \ulink{InputOnly}
Fred Drake666ca802001-11-16 06:02:55 +00001381{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
1382widgets are to accept inputs from the user, which can be done with the
1383\code{bind} command (\UNIX{} only).
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001384\end{classdesc}
1385
1386\subsubsection{Form Geometry Manager}
1387
1388In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
Fred Drake666ca802001-11-16 06:02:55 +00001389
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001390\begin{classdesc}{Form}{}
1391The \ulink{Form}
Fred Drake666ca802001-11-16 06:02:55 +00001392{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
1393geometry manager based on attachment rules for all Tk widgets.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001394\end{classdesc}
1395
1396
1397%begin{latexonly}
1398%\subsection{Tix Class Structure}
1399%
1400%\begin{figure}[hbtp]
1401%\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
1402%\vspace{.5cm}
1403%\caption{The Class Hierarchy of Tix Widgets}
1404%\end{figure}
1405%end{latexonly}
1406
Fred Drake44b6f842001-11-29 21:09:08 +00001407\subsection{Tix Commands}
1408
1409\begin{classdesc}{tixCommand}{}
1410The \ulink{tix commands}
1411{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
1412provide access to miscellaneous elements of \refmodule{Tix}'s internal
1413state and the \refmodule{Tix} application context. Most of the information
1414manipulated by these methods pertains to the application as a whole,
1415or to a screen or display, rather than to a particular window.
1416
1417To view the current settings, the common usage is:
1418\begin{verbatim}
1419import Tix
1420root = Tix.Tk()
1421print root.tix_configure()
1422\end{verbatim}
1423\end{classdesc}
1424
1425\begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
1426Query or modify the configuration options of the Tix application
1427context. If no option is specified, returns a dictionary all of the
1428available options. If option is specified with no value, then the
1429method returns a list describing the one named option (this list will
1430be identical to the corresponding sublist of the value returned if no
1431option is specified). If one or more option-value pairs are
1432specified, then the method modifies the given option(s) to have the
1433given value(s); in this case the method returns an empty string.
1434Option may be any of the configuration options.
1435\end{methoddesc}
1436
1437\begin{methoddesc}{tix_cget}{option}
1438Returns the current value of the configuration option given by
1439\var{option}. Option may be any of the configuration options.
1440\end{methoddesc}
1441
1442\begin{methoddesc}{tix_getbitmap}{name}
1443Locates a bitmap file of the name \code{name.xpm} or \code{name} in
1444one of the bitmap directories (see the \method{tix_addbitmapdir()}
1445method). By using \method{tix_getbitmap()}, you can avoid hard
1446coding the pathnames of the bitmap files in your application. When
1447successful, it returns the complete pathname of the bitmap file,
1448prefixed with the character \samp{@}. The returned value can be used to
1449configure the \code{bitmap} option of the Tk and Tix widgets.
1450\end{methoddesc}
1451
1452\begin{methoddesc}{tix_addbitmapdir}{directory}
1453Tix maintains a list of directories under which the
1454\method{tix_getimage()} and \method{tix_getbitmap()} methods will
1455search for image files. The standard bitmap directory is
1456\file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
1457adds \var{directory} into this list. By using this method, the image
1458files of an applications can also be located using the
1459\method{tix_getimage()} or \method{tix_getbitmap()} method.
1460\end{methoddesc}
1461
1462\begin{methoddesc}{tix_filedialog}{\optional{dlgclass}}
1463Returns the file selection dialog that may be shared among different
1464calls from this application. This method will create a file selection
1465dialog widget when it is called the first time. This dialog will be
1466returned by all subsequent calls to \method{tix_filedialog()}. An
1467optional dlgclass parameter can be passed as a string to specified
1468what type of file selection dialog widget is desired. Possible
1469options are \code{tix}, \code{FileSelectDialog} or
1470\code{tixExFileSelectDialog}.
1471\end{methoddesc}
1472
1473
1474\begin{methoddesc}{tix_getimage}{self, name}
1475Locates an image file of the name \file{name.xpm}, \file{name.xbm} or
1476\file{name.ppm} in one of the bitmap directories (see the
1477\method{tix_addbitmapdir()} method above). If more than one file with
1478the same name (but different extensions) exist, then the image type is
1479chosen according to the depth of the X display: xbm images are chosen
1480on monochrome displays and color images are chosen on color
1481displays. By using \method{tix_getimage()}, you can avoid hard coding
1482the pathnames of the image files in your application. When successful,
1483this method returns the name of the newly created image, which can be
1484used to configure the \code{image} option of the Tk and Tix widgets.
1485\end{methoddesc}
1486
1487\begin{methoddesc}{tix_option_get}{name}
1488Gets the options manitained by the Tix scheme mechanism.
1489\end{methoddesc}
1490
1491\begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
1492 newScmPrio}}
1493Resets the scheme and fontset of the Tix application to
1494\var{newScheme} and \var{newFontSet}, respectively. This affects only
1495those widgets created after this call. Therefore, it is best to call
1496the resetoptions method before the creation of any widgets in a Tix
1497application.
1498
1499The optional parameter \var{newScmPrio} can be given to reset the
1500priority level of the Tk options set by the Tix schemes.
1501
1502Because of the way Tk handles the X option database, after Tix has
1503been has imported and inited, it is not possible to reset the color
1504schemes and font sets using the \method{tix_config()} method.
1505Instead, the \method{tix_resetoptions()} method must be used.
1506\end{methoddesc}
1507
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001508
Fred Drakec66ff202001-11-16 01:05:27 +00001509\input{libturtle}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001510
1511
1512\section{Idle \label{idle}}
1513
1514%\declaremodule{standard}{idle}
1515%\modulesynopsis{A Python Integrated Developement Environment}
1516\moduleauthor{Guido van Rossum}{guido@Python.org}
1517
1518Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
1519\index{Idle}
1520\index{Python Editor}
1521\index{Integrated Developement Environment}
1522
1523
1524IDLE has the following features:
1525
1526\begin{itemize}
1527\item coded in 100\% pure Python, using the \refmodule{Tkinter} GUI toolkit
1528
1529\item cross-platform: works on Windows and \UNIX{} (on Mac OS, there are
1530currently problems with Tcl/Tk)
1531
1532\item multi-window text editor with multiple undo, Python colorizing
1533and many other features, e.g. smart indent and call tips
1534
1535\item Python shell window (a.k.a. interactive interpreter)
1536
1537\item debugger (not complete, but you can set breakpoints, view and step)
1538\end{itemize}
1539
1540
1541\subsection{Menus}
1542
1543\subsubsection{File menu}
1544
1545\begin{description}
1546\item[New window] create a new editing window
1547\item[Open...] open an existing file
1548\item[Open module...] open an existing module (searches sys.path)
1549\item[Class browser] show classes and methods in current file
1550\item[Path browser] show sys.path directories, modules, classes and methods
1551\end{description}
1552\index{Class browser}
1553\index{Path browser}
1554
1555\begin{description}
1556\item[Save] save current window to the associated file (unsaved
1557windows have a * before and after the window title)
1558
1559\item[Save As...] save current window to new file, which becomes
1560the associated file
1561\item[Save Copy As...] save current window to different file
1562without changing the associated file
1563\end{description}
1564
1565\begin{description}
1566\item[Close] close current window (asks to save if unsaved)
1567\item[Exit] close all windows and quit IDLE (asks to save if unsaved)
1568\end{description}
1569
1570
1571\subsubsection{Edit menu}
1572
1573\begin{description}
1574\item[Undo] Undo last change to current window (max 1000 changes)
1575\item[Redo] Redo last undone change to current window
1576\end{description}
1577
1578\begin{description}
1579\item[Cut] Copy selection into system-wide clipboard; then delete selection
1580\item[Copy] Copy selection into system-wide clipboard
1581\item[Paste] Insert system-wide clipboard into window
1582\item[Select All] Select the entire contents of the edit buffer
1583\end{description}
1584
1585\begin{description}
1586\item[Find...] Open a search dialog box with many options
1587\item[Find again] Repeat last search
1588\item[Find selection] Search for the string in the selection
1589\item[Find in Files...] Open a search dialog box for searching files
1590\item[Replace...] Open a search-and-replace dialog box
1591\item[Go to line] Ask for a line number and show that line
1592\end{description}
1593
1594\begin{description}
1595\item[Indent region] Shift selected lines right 4 spaces
1596\item[Dedent region] Shift selected lines left 4 spaces
1597\item[Comment out region] Insert \#\# in front of selected lines
1598\item[Uncomment region] Remove leading \# or \#\# from selected lines
1599\item[Tabify region] Turns \emph{leading} stretches of spaces into tabs
1600\item[Untabify region] Turn \emph{all} tabs into the right number of spaces
1601\item[Expand word] Expand the word you have typed to match another
1602 word in the same buffer; repeat to get a different expansion
1603\item[Format Paragraph] Reformat the current blank-line-separated paragraph
1604\end{description}
1605
1606\begin{description}
1607\item[Import module] Import or reload the current module
1608\item[Run script] Execute the current file in the __main__ namespace
1609\end{description}
1610
1611\index{Import module}
1612\index{Run script}
1613
1614
1615\subsubsection{Windows menu}
1616
1617\begin{description}
1618\item[Zoom Height] toggles the window between normal size (24x80)
1619 and maximum height.
1620\end{description}
1621
1622The rest of this menu lists the names of all open windows; select one
1623to bring it to the foreground (deiconifying it if necessary).
1624
1625
1626\subsubsection{Debug menu (in the Python Shell window only)}
1627
1628\begin{description}
1629\item[Go to file/line] look around the insert point for a filename
1630 and linenumber, open the file, and show the line.
1631\item[Open stack viewer] show the stack traceback of the last exception
1632\item[Debugger toggle] Run commands in the shell under the debugger
1633\item[JIT Stack viewer toggle] Open stack viewer on traceback
1634\end{description}
1635
1636\index{stack viewer}
1637\index{debugger}
1638
1639
1640\subsection{Basic editing and navigation}
1641
1642\begin{itemize}
1643\item \kbd{Backspace} deletes to the left; \kbd{Del} deletes to the right
1644\item Arrow keys and \kbd{Page Up}/\kbd{Page Down} to move around
1645\item \kbd{Home}/\kbd{End} go to begin/end of line
1646\item \kbd{C-Home}/\kbd{C-End} go to begin/end of file
1647\item Some \program{Emacs} bindings may also work, including \kbd{C-B},
1648 \kbd{C-P}, \kbd{C-A}, \kbd{C-E}, \kbd{C-D}, \kbd{C-L}
1649\end{itemize}
1650
1651
1652\subsubsection{Automatic indentation}
1653
1654After a block-opening statement, the next line is indented by 4 spaces
1655(in the Python Shell window by one tab). After certain keywords
1656(break, return etc.) the next line is dedented. In leading
1657indentation, \kbd{Backspace} deletes up to 4 spaces if they are there.
1658\kbd{Tab} inserts 1-4 spaces (in the Python Shell window one tab).
1659See also the indent/dedent region commands in the edit menu.
1660
1661
1662\subsubsection{Python Shell window}
1663
1664\begin{itemize}
1665\item \kbd{C-C} interrupts executing command
1666\item \kbd{C-D} sends end-of-file; closes window if typed at
1667a \samp{>>>~} prompt
1668\end{itemize}
1669
1670\begin{itemize}
Fred Drake666ca802001-11-16 06:02:55 +00001671\item \kbd{Alt-p} retrieves previous command matching what you have typed
1672\item \kbd{Alt-n} retrieves next
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001673\item \kbd{Return} while on any previous command retrieves that command
Fred Drake666ca802001-11-16 06:02:55 +00001674\item \kbd{Alt-/} (Expand word) is also useful here
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001675\end{itemize}
1676
1677\index{indentation}
1678
1679
1680\subsection{Syntax colors}
1681
1682The coloring is applied in a background ``thread,'' so you may
1683occasionally see uncolorized text. To change the color
1684scheme, edit the \code{[Colors]} section in \file{config.txt}.
1685
1686\begin{description}
1687\item[Python syntax colors:]
1688
1689\begin{description}
1690\item[Keywords] orange
1691\item[Strings ] green
1692\item[Comments] red
1693\item[Definitions] blue
1694\end{description}
1695
1696\item[Shell colors:]
1697\begin{description}
1698\item[Console output] brown
1699\item[stdout] blue
1700\item[stderr] dark green
1701\item[stdin] black
1702\end{description}
1703\end{description}
1704
1705
1706\subsubsection{Command line usage}
1707
1708\begin{verbatim}
1709idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
1710
1711-c command run this command
1712-d enable debugger
1713-e edit mode; arguments are files to be edited
1714-s run $IDLESTARTUP or $PYTHONSTARTUP first
1715-t title set title of shell window
1716\end{verbatim}
1717
1718If there are arguments:
1719
1720\begin{enumerate}
1721\item If \programopt{-e} is used, arguments are files opened for
1722 editing and \code{sys.argv} reflects the arguments passed to
1723 IDLE itself.
1724
1725\item Otherwise, if \programopt{-c} is used, all arguments are
1726 placed in \code{sys.argv[1:...]}, with \code{sys.argv[0]} set
1727 to \code{'-c'}.
1728
1729\item Otherwise, if neither \programopt{-e} nor \programopt{-c} is
1730 used, the first argument is a script which is executed with
1731 the remaining arguments in \code{sys.argv[1:...]} and
1732 \code{sys.argv[0]} set to the script name. If the script name
1733 is '-', no script is executed but an interactive Python
1734 session is started; the arguments are still available in
1735 \code{sys.argv}.
1736\end{enumerate}
Fred Drakec66ff202001-11-16 01:05:27 +00001737
1738
1739\section{Other Graphical User Interface Packages
1740 \label{other-gui-packages}}
1741
1742
1743There are an number of extension widget sets to \refmodule{Tkinter}.
1744
Fred Drake10cd3152001-11-30 18:17:24 +00001745\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001746\seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
1747toolkit for building high-level compound widgets in Python using the
1748\refmodule{Tkinter} module. It consists of a set of base classes and
1749a library of flexible and extensible megawidgets built on this
1750foundation. These megawidgets include notebooks, comboboxes, selection
1751widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1752with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1753and vector commands are be available.
1754
1755The initial ideas for Pmw were taken from the Tk \code{itcl}
1756extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
1757Widgets]} by Mark Ulferts. Several of the megawidgets are direct
1758translations from the itcl to Python. It offers most of the range of
1759widgets that \code{[incr Widgets]} does, and is almost as complete as
1760Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
1761}
1762\seetitle[http://tkinter.effbot.org]{Tkinter3000}{
1763is a Widget Construction Kit that allows you to write new Tkinter
1764widgets in Python using Mixins. It is built on top of Tkinter,
1765and does not offer the extended range of widgets that \refmodule{Tix} does,
1766but does allow a form of building mega-widgets. The project is
1767still in the early stages.
1768}
Fred Drake10cd3152001-11-30 18:17:24 +00001769\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001770
1771
Fred Drake666ca802001-11-16 06:02:55 +00001772Tk is not the only GUI for Python, but is however the
Fred Drakec66ff202001-11-16 01:05:27 +00001773most commonly used one.
1774
Fred Drake10cd3152001-11-30 18:17:24 +00001775\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001776\seetitle[http://www.wxwindows.org]{wxWindows}{
1777is a GUI toolkit that combines the most attractive attributes of Qt,
1778Tk, Motif, and GTK+ in one powerful and efficient package. It is
Fred Drakec37b65e2001-11-28 07:26:15 +00001779implemented in \Cpp. wxWindows supports two flavors of \UNIX{}
Fred Drakec66ff202001-11-16 01:05:27 +00001780implementation: GTK+ and Motif, and under Windows, it has a standard
1781Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1782widgets. There is a Python class wrapper, independent of Tkinter.
1783
1784wxWindows is much richer in widgets than \refmodule{Tkinter}, with its
1785help system, sophisticated HTML and image viewers, and other
1786specialized widgets, extensive documentation, and printing capabilities.
1787}
1788\seetitle[http://www.thekompany.com]{PyKDE}{
1789PyKDE is a SIP wrapped interface to the Qt toolkit.
1790The Qt \Cpp{} toolkit lies at the heart of the KDE desktop, and the
1791Qt toolkit allows very tight integration with KDE, and also Windows
1792portability. SIP is a tool for generating bindings for \Cpp{} libraries
1793as Python classes, and is specifically designed for Python.
1794}
1795\seetitle[http://fxpy.sourceforge.net/]{FXPy}{
1796is a Python extension module which provides an interface to the
1797\citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
1798FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
1799easily and effectively. It offers a wide, and growing, collection of
1800Controls, and provides state of the art facilities such as drag and
1801drop, selection, as well as OpenGL widgets for 3D graphical
1802manipulation. FOX also implements icons, images, and user-convenience
1803features such as status line help, and tooltips.
1804
1805Even though FOX offers a large collection of controls already, FOX
1806leverages \Cpp{} to allow programmers to easily build additional Controls
1807and GUI elements, simply by taking existing controls, and creating a
1808derived class which simply adds or redefines the desired behavior.
1809}
1810\seetitle[http://www.daa.com.au/\~james/pygtk/]{PyGTK}{
1811is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
1812It provides an object oriented interface that is slightly higher
1813level than the C one. It automatically does all the type casting and
1814reference counting that you would have to do normally with the C
1815API. There are also \ulink{bindings}{http://www.daa.com.au/\~james/gnome/}
1816to \ulink{GNOME}{http://www.gnome.org}, and a
1817\ulink{tutorial}
1818{http://laguna.fmedic.unam.mx/\~daniel/pygtutorial/pygtutorial/index.html}
1819is available.
1820}
Fred Drake10cd3152001-11-30 18:17:24 +00001821\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001822
1823% XXX Reference URLs that compare the different UI packages