blob: 91d7c79c910f1930c4de86f3509ad9b529330f68 [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
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000249
Fred Drakeb22c6722001-12-03 06:12:23 +0000250\subsection{A (Very) Quick Look at Tcl/Tk} % BriefTclTk.html
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000251
252The class hierarchy looks complicated, but in actual practice,
253application programmers almost always refer to the classes at the very
254bottom of the hierarchy.
255
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000256Notes:
257\begin{itemize}
258\item These classes are provided for the purposes of
259organizing certain functions under one namespace. They aren't meant to
260be instantiated independently.
Fred Drakeb22c6722001-12-03 06:12:23 +0000261
262\item The \class{Tk} class is meant to be instantiated only once in
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000263an application. Application programmers need not instantiate one
264explicitly, the system creates one whenever any of the other classes
265are instantiated.
Fred Drakeb22c6722001-12-03 06:12:23 +0000266
267\item The \class{Widget} class is not meant to be instantiated, it
268is meant only for subclassing to make ``real'' widgets (in \Cpp, this
269is called an `abstract class').
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000270\end{itemize}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000271
272To make use of this reference material, there will be times when you
273will need to know how to read short passages of Tk and how to identify
274the various parts of a Tk command.
Fred Drake666ca802001-11-16 06:02:55 +0000275(See section~\ref{tkinter-basic-mapping} for the
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000276\refmodule{Tkinter} equivalents of what's below.)
277
278Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
279just lists of tokens separated by spaces. A Tk widget is just its
280\emph{class}, the \emph{options} that help configure it, and the
281\emph{actions} that make it do useful things.
282
283To make a widget in Tk, the command is always of the form:
284
285\begin{verbatim}
286 classCommand newPathname options
287\end{verbatim}
288
289\begin{description}
290\item[\var{classCommand}]
291denotes which kind of widget to make (a button, a label, a menu...)
292
293\item[\var{newPathname}]
294is the new name for this widget. All names in Tk must be unique. To
295help enforce this, widgets in Tk are named with \emph{pathnames}, just
296like files in a file system. The top level widget, the \emph{root},
297is called \code{.} (period) and children are delimited by more
298periods. For example, \code{.myApp.controlPanel.okButton} might be
299the name of a widget.
300
301\item[\var{options} ]
302configure the widget's appearance and in some cases, its
303behavior. The options come in the form of a list of flags and values.
304Flags are proceeded by a `-', like unix shell command flags, and
305values are put in quotes if they are more than one word.
306\end{description}
307
308For example:
309
310\begin{verbatim}
311 button .fred -fg red -text "hi there"
312 ^ ^ \_____________________/
313 | | |
314 class new options
315 command widget (-opt val -opt val ...)
316\end{verbatim}
317
318Once created, the pathname to the widget becomes a new command. This
319new \var{widget command} is the programmer's handle for getting the new
320widget to perform some \var{action}. In C, you'd express this as
Fred Drakec66ff202001-11-16 01:05:27 +0000321someAction(fred, someOptions), in \Cpp, you would express this as
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000322fred.someAction(someOptions), and in Tk, you say:
323
324\begin{verbatim}
325 .fred someAction someOptions
326\end{verbatim}
327
328Note that the object name, \code{.fred}, starts with a dot.
329
330As you'd expect, the legal values for \var{someAction} will depend on
331the widget's class: \code{.fred disable} works if fred is a
332button (fred gets greyed out), but does not work if fred is a label
333(disabling of labels is not supported in Tk).
334
335The legal values of \var{someOptions} is action dependent. Some
336actions, like \code{disable}, require no arguments, others, like
337a text-entry box's \code{delete} command, would need arguments
338to specify what range of text to delete.
339
340
341\subsection{Mapping Basic Tk into Tkinter
342 \label{tkinter-basic-mapping}}
343
344Class commands in Tk correspond to class constructors in Tkinter.
345
346\begin{verbatim}
347 button .fred =====> fred = Button()
348\end{verbatim}
349
350The master of an object is implicit in the new name given to it at
351creation time. In Tkinter, masters are specified explicitly.
352
353\begin{verbatim}
354 button .panel.fred =====> fred = Button(panel)
355\end{verbatim}
356
357The configuration options in Tk are given in lists of hyphened tags
358followed by values. In Tkinter, options are specified as
359keyword-arguments in the instance constructor, and keyword-args for
360configure calls or as instance indices, in dictionary style, for
Fred Drake666ca802001-11-16 06:02:55 +0000361established instances. See section~\ref{tkinter-setting-options} on
362setting options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000363
364\begin{verbatim}
365 button .fred -fg red =====> fred = Button(panel, fg = "red")
366 .fred configure -fg red =====> fred["fg"] = red
367 OR ==> fred.config(fg = "red")
368\end{verbatim}
369
370In Tk, to perform an action on a widget, use the widget name as a
371command, and follow it with an action name, possibly with arguments
372(options). In Tkinter, you call methods on the class instance to
373invoke actions on the widget. The actions (methods) that a given
374widget can perform are listed in the Tkinter.py module.
375
376\begin{verbatim}
377 .fred invoke =====> fred.invoke()
378\end{verbatim}
379
380To give a widget to the packer (geometry manager), you call pack with
381optional arguments. In Tkinter, the Pack class holds all this
382functionality, and the various forms of the pack command are
383implemented as methods. All widgets in \refmodule{Tkinter} are
384subclassed from the Packer, and so inherit all the packing
385methods. See the \refmodule{Tix} module documentation for additional
386information on the Form geometry manager.
387
388\begin{verbatim}
389 pack .fred -side left =====> fred.pack(side = "left")
390\end{verbatim}
391
392
393\subsection{How Tk and Tkinter are Related} % Relationship.html
394
Fred Drake666ca802001-11-16 06:02:55 +0000395\note{This was derived from a graphical image; the image will be used
396 more directly in a subsequent version of this document.}
397
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000398From the top down:
399\begin{description}
400\item[\b{Your App Here (Python)}]
401A Python application makes a \refmodule{Tkinter} call.
402
403\item[\b{Tkinter (Python Module)}]
404This call (say, for example, creating a button widget), is
405implemented in the \emph{Tkinter} module, which is written in
406Python. This Python function will parse the commands and the
407arguments and convert them into a form that makes them look as if they
408had come from a Tk script instead of a Python script.
409
410\item[\b{tkinter (C)}]
411These commands and their arguments will be passed to a C function
412in the \emph{tkinter} - note the lowercase - extension module.
413
414\item[\b{Tk Widgets} (C and Tcl)]
415This C function is able to make calls into other C modules,
416including the C functions that make up the Tk library. Tk is
417implemented in C and some Tcl. The Tcl part of the Tk widgets is used
418to bind certain default behaviors to widgets, and is executed once at
419the point where the Python \refmodule{Tkinter} module is
420imported. (The user never sees this stage).
421
422\item[\b{Tk (C)}]
423The Tk part of the Tk Widgets implement the final mapping to ...
424
425\item[\b{Xlib (C)}]
426the Xlib library to draw graphics on the screen.
427\end{description}
428
429
430\subsection{Handy Reference}
431
432\subsubsection{Setting Options
433 \label{tkinter-setting-options}}
434
435Options control things like the color and border width of a widget.
436Options can be set in three ways:
437
438\begin{description}
439\item[At object creation time, using keyword arguments]:
440\begin{verbatim}
441fred = Button(self, fg = "red", bg = "blue")
442\end{verbatim}
443\item[After object creation, treating the option name like a dictionary index]:
444\begin{verbatim}
445fred["fg"] = "red"
446fred["bg"] = "blue"
447\end{verbatim}
448\item[Use the config() method to update multiple attrs subesequent to
449object creation]:
450\begin{verbatim}
451fred.config(fg = "red", bg = "blue")
452\end{verbatim}
453\end{description}
454
455For a complete explanation of a given option and its behavior, see the
456Tk man pages for the widget in question.
457
458Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
459OPTIONS" for each widget. The former is a list of options that are
460common to many widgets, the latter are the options that are
461ideosyncratic to that particular widget. The Standard Options are
462documented on the \manpage{options}{3} man page.
463
464No distinction between standard and widget-specific options is made in
465this document. Some options don't apply to some kinds of widgets.
466Whether a given widget responds to a particular option depends on the
467class of the widget; buttons have a \code{command} option, labels do not.
468
469The options supported by a given widget are listed in that widget's
470man page, or can be queried at runtime by calling the
471\kbd{config()} method with arguments, or by calling the keys()
472method on that widget. The return value of these calls is a dictionary
473whose key is the name of the option (e.g. \kbd{relief}) and whose
474values are 5 tuples.
475
476(Some options, like \kbd{bg} are synonyms for common options with
477hard-to-type names (\kbd{bg} is shorthand for "background").
478Passing the \kbd{config()} method the name of a
479shorthand option will return a 2-tuple, not 5-tuple. The 2-tuple
480passed back will contain the name of the synonym ``real''
481option. (\kbd{bg}, \kbd{background}))
482
483\begin{tableiii}{c|l|l}{textrm}{Index}{Meaning}{Example}
484 \lineiii{0}{option name} {\code{'relief'}}
485 \lineiii{1}{option name for database lookup} {\code{'relief'}}
486 \lineiii{2}{option class for database lookup} {\code{'Relief'}}
487 \lineiii{3}{default value} {\code{'raised'}}
488 \lineiii{4}{current value} {\code{'groove'}}
489\end{tableiii}
490
491
492Example:
493
494\begin{verbatim}
495>>> print fred.config()
496{'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}
497\end{verbatim}
498
499Of course, the dictionary printed will include all the options
500available and their values. This is meant only as an example.
501
502
503\subsubsection{The Packer} % Packer.html
504\index{packing (widgets)}
505
506The packer is one of Tk's geometry-management mechanisms. See also
507\citetitle[classes/ClassPacker.html]{the Packer class interface}.
508
509Geometry managers are used to specify the relative positioning of the
510positioning of widgets within their container - their mutual
511\emph{master}. In contrast to the more cumbersome \emph{placer}
512(which is used less commonly, and we do not cover here), the packer
513takes qualitative relationship specification - \emph{above}, \emph{to
514the left of}, \emph{filling}, etc - and works everything out to
515determine the exact placement coordinates for you.
516
517The size of any \emph{master} widget is determined by the size of
518the "slave widgets" inside. The packer is used to control where slave
519widgets appear inside the master into which they are packed. You can
520pack widgets into frames, and frames into other frames, in order to
521achieve the kind of layout you desire. Additionally, the arrangement
522is dynamically adjusted to accomodate incremental changes to the
523configuration, once it is packed.
524
525Note that widgets do not appear until they have had their geometry
526specified with a geometry manager. It's a common early mistake to
527leave out the geometry specification, and then be surprised when the
528widget is created but nothing appears. A widget will appear only
529after it has had, for example, the packer's \method{pack()} method
530applied to it.
531
532The pack() method can be called with keyword-option/value pairs that
533control where the widget is to appear within its container, and how it
534is to behave when the main application window is resized. Here are
535some examples:
536
537\begin{verbatim}
538 fred.pack() # defaults to side = "top"
539 fred.pack(side = "left")
540 fred.pack(expand = 1)
541\end{verbatim}
542
543
544\subsubsection{Packer Options}
545
546For more extensive information on the packer and the options that it
547can take, see the man pages and page 183 of John Ousterhout's book.
548
549\begin{description}
550\item[\b{anchor }]
551Anchor type. Denotes where the packer is to place each slave in its
552parcel.
553
554\item[\b{expand}]
555Boolean, \code{0} or \code{1}.
556
557\item[\b{fill}]
558Legal values: \code{'x'}, \code{'y'}, \code{'both'}, \code{'none'}.
559
560\item[\b{ipadx} and \b{ipady}]
561A distance - designating internal padding on each side of the slave
562widget.
563
564\item[\b{padx} and \b{pady}]
565A distance - designating external padding on each side of the slave
566widget.
567
568\item[\b{side}]
569Legal values are: \code{'left'}, \code{'right'}, \code{'top'},
570\code{'bottom'}.
571\end{description}
572
573
574\subsubsection{Coupling Widget Variables} % VarCouplings.html
575
576The current-value setting of some widgets (like text entry widgets)
577can be connected directly to application variables by using special
578options. These options are \code{variable}, \code{textvariable},
579\code{onvalue}, \code{offvalue}, and \code{value}. This
580connection works both ways: if the variable changes for any reason,
581the widget it's connected to will be updated to reflect the new value.
582
583Unfortunately, in the current implementation of \refmodule{Tkinter} it is
584not possible to hand over an arbitrary Python variable to a widget
585through a \code{variable} or \code{textvariable} option. The only
586kinds of variables for which this works are variables that are
587subclassed from a class called Variable, defined in the
588\refmodule{Tkinter} module.
589
590There are many useful subclasses of Variable already defined:
591\class{StringVar}, \class{IntVar}, \class{DoubleVar}, and
592\class{BooleanVar}. To read the current value of such a variable,
593call the \method{get()} method on
594it, and to change its value you call the \method{set()} method. If
595you follow this protocol, the widget will always track the value of
596the variable, with no further intervention on your part.
597
598For example:
599\begin{verbatim}
600class App(Frame):
601 def __init__(self, master=None):
602 Frame.__init__(self, master)
603 self.pack()
604
605 self.entrythingy = Entry()
606 self.entrythingy.pack()
607
608 self.button.pack()
609 # here is the application variable
610 self.contents = StringVar()
611 # set it to some value
612 self.contents.set("this is a variable")
613 # tell the entry widget to watch this variable
614 self.entrythingy["textvariable"] = self.contents
615
616 # and here we get a callback when the user hits return.
617 # we will have the program print out the value of the
618 # application variable when the user hits return
619 self.entrythingy.bind('<Key-Return>',
620 self.print_contents)
621
622 def print_contents(self, event):
623 print "hi. contents of entry is now ---->", \
624 self.contents.get()
625\end{verbatim}
626
627
628\subsubsection{The Window Manager} % WindowMgr.html
629\index{window manager (widgets)}
630
631In Tk, there is a utility command, \code{wm}, for interacting with the
632window manager. Options to the \code{wm} command allow you to control
633things like titles, placement, icon bitmaps, and the like. In
634\refmodule{Tkinter}, these commands have been implemented as methods
635on the \class{Wm} class. Toplevel widgets are subclassed from the
636\class{Wm} class, and so can call the \class{Wm} methods directly.
637
638%See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
639
640To get at the toplevel window that contains a given widget, you can
641often just refer to the widget's master. Of course if the widget has
642been packed inside of a frame, the master won't represent a toplevel
643window. To get at the toplevel window that contains an arbitrary
644widget, you can call the \method{_root()} method. This
645method begins with an underscore to denote the fact that this function
646is part of the implementation, and not an interface to Tk functionality.
647
648Here are some examples of typical usage:
649
650\begin{verbatim}
651import Tkinter
652class App(Frame):
653 def __init__(self, master=None):
654 Frame.__init__(self, master)
655 self.pack()
656
657
658# create the application
659myapp = App()
660
661#
662# here are method calls to the window manager class
663#
664myapp.master.title("My Do-Nothing Application")
665myapp.master.maxsize(1000, 400)
666
667# start the program
668myapp.mainloop()
669\end{verbatim}
670
671
672\subsubsection{Tk Option Data Types} % OptionTypes.html
673
674\index{Tk Option Data Types}
675
676\begin{description}
677\item[anchor]
678Legal values are points of the compass: \code{"n"},
679\code{"ne"}, \code{"e"}, \code{"se"}, \code{"s"},
680\code{"sw"}, \code{"w"}, \code{"nw"}, and also
681\code{"center"}.
682
683\item[bitmap]
684There are eight built-in, named bitmaps: \code{'error'}, \code{'gray25'},
685\code{'gray50'}, \code{'hourglass'}, \code{'info'}, \code{'questhead'},
686\code{'question'}, \code{'warning'}. To specify an X bitmap
687filename, give the full path to the file, preceded with an \code{@},
688as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
689
690\item[boolean]
691You can pass integers 0 or 1 or the stings \code{"yes"} or \code{"no"} .
692
693\item[callback]
694This is any Python function that takes no arguments. For example:
695\begin{verbatim}
696 def print_it():
697 print "hi there"
698 fred["command"] = print_it
699\end{verbatim}
700
701\item[color]
702Colors can be given as the names of X colors in the rgb.txt file,
703or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
704bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
705\code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
706legal hex digit. See page 160 of Ousterhout's book for details.
707
708\item[cursor]
709The standard X cursor names from \file{cursorfont.h} can be used,
710without the \code{XC_} prefix. For example to get a hand cursor
711(\constant{XC_hand2}), use the string \code{"hand2"}. You can also
712specify a bitmap and mask file of your own. See page 179 of
713Ousterhout's book.
714
715\item[distance]
716Screen distances can be specified in either pixels or absolute
717distances. Pixels are given as numbers and absolute distances as
718strings, with the trailing character denoting units: \code{c}
719for centimeters, \code{i} for inches, \code{m} for millimeters,
720\code{p} for printer's points. For example, 3.5 inches is expressed
721as \code{"3.5i"}.
722
723\item[font]
724Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
725Font sizes with positive numbers are measured in points;
726sizes with negative numbers are measured in pixels.
727
728\item[geometry]
729This is a string of the form \samp{\var{width}x\var{height}}, where
730width and height are measured in pixels for most widgets (in
731characters for widgets displaying text). For example:
732\code{fred["geometry"] = "200x100"}.
733
734\item[justify]
735Legal values are the strings: \code{"left"},
736\code{"center"}, \code{"right"}, and \code{"fill"}.
737
738\item[region]
739This is a string with four space-delimited elements, each of
740which is a legal distance (see above). For example: \code{"2 3 4
7415"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
742are all legal regions.
743
744\item[relief]
745Determines what the border style of a widget will be. Legal
746values are: \code{"raised"}, \code{"sunken"},
747\code{"flat"}, \code{"groove"}, and \code{"ridge"}.
748
749\item[scrollcommand]
750This is almost always the \method{set()} method of some scrollbar
751widget, but can be any widget method that takes a single argument.
752Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
753in the Python source distribution for an example.
754
755\item[wrap:]
756Must be one of: \code{"none"}, \code{"char"}, or \code{"word"}.
757\end{description}
758
759
760\subsubsection{Bindings and Events} % Bindings.html
761
762\index{bind (widgets)}
763\index{events (widgets)}
764
765The bind method from the widget command allows you to watch for
766certain events and to have a callback function trigger when that event
767type occurs. The form of the bind method is:
768
769\begin{verbatim}
770 def bind(self, sequence, func, add=''):
771\end{verbatim}
772where:
773
774\begin{description}
775\item[sequence]
776is a string that denotes the target kind of event. (See the bind
777man page and page 201 of John Ousterhout's book for details).
778
779\item[func]
780is a Python function, taking one argument, to be invoked when the
781event occurs. An Event instance will be passed as the argument.
782(Functions deployed this way are commonly known as \var{callbacks}.)
783
784\item[add]
785is optional, either \samp{} or \samp{+}. Passing an empty string
786denotes that this binding is to replace any other bindings that this
787event is associated with. Preceeding with a \samp{+} means that this
788function is to be added to the list of functions bound to this event type.
789\end{description}
790
791For example:
792\begin{verbatim}
793 def turnRed(self, event):
794 event.widget["activeforeground"] = "red"
795
796 self.button.bind("<Enter>", self.turnRed)
797\end{verbatim}
798
799Notice how the widget field of the event is being accesed in the
800\method{turnRed()} callback. This field contains the widget that
801caught the X event. The following table lists the other event fields
802you can access, and how they are denoted in Tk, which can be useful
803when referring to the Tk man pages.
804
805\begin{verbatim}
806Tk Tkinter Event Field Tk Tkinter Event Field
807-- ------------------- -- -------------------
808%f focus %A char
809%h height %E send_event
810%k keycode %K keysym
811%s state %N keysym_num
812%t time %T type
813%w width %W widget
814%x x %X x_root
815%y y %Y y_root
816\end{verbatim}
817
818
819\subsubsection{The index Parameter} % Index.html
820
821A number of widgets require``index'' parameters to be passed. These
822are used to point at a specific place in a Text widget, or to
823particular characters in an Entry widget, or to particular menu items
824in a Menu widget.
825
826\begin{description}
827\item[\b{Entry widget indexes (index, view index, etc.)}]
828Entry widgets have options that refer to character positions in the
829text being displayed. You can use these \refmodule{Tkinter} functions
830to access these special points in text widgets:
Fred Drake666ca802001-11-16 06:02:55 +0000831
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000832\begin{description}
833\item[AtEnd()]
834refers to the last position in the text
Fred Drake666ca802001-11-16 06:02:55 +0000835
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000836\item[AtInsert()]
837refers to the point where the text cursor is
Fred Drake666ca802001-11-16 06:02:55 +0000838
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000839\item[AtSelFirst()]
840indicates the beginning point of the selected text
Fred Drake666ca802001-11-16 06:02:55 +0000841
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000842\item[AtSelLast()]
843denotes the last point of the selected text and finally
Fred Drake666ca802001-11-16 06:02:55 +0000844
845\item[At(x\optional{, y})]
846refers to the character at pixel location \var{x}, \var{y} (with
847\var{y} not used in the case of a text entry widget, which contains a
848single line of text).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000849\end{description}
850
851\item[\b{Text widget indexes}]
852The index notation for Text widgets is very rich and is best described
853in the Tk man pages.
854
855\item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
856
857Some options and methods for menus manipulate specific menu entries.
858Anytime a menu index is needed for an option or a parameter, you may
859pass in:
860\begin{itemize}
861\item an integer which refers to the numeric position of the entry in
862the widget, counted from the top, starting with 0;
863\item the string \code{'active'}, which refers to the menu position that is
864currently under the cursor;
865\item the string \code{"last"} which refers to the last menu
866item;
867\item An integer preceded by \code{@}, as in \code{@6}, where the integer is
868interpreted as a y pixel coordinate in the menu's coordinate system;
869\item the string \code{"none"}, which indicates no menu entry at all, most
870often used with menu.activate() to deactivate all entries, and
871finally,
872\item a text string that is pattern matched against the label of the
873menu entry, as scanned from the top of the menu to the bottom. Note
874that this index type is considered after all the others, which means
875that matches for menu items labelled \code{last}, \code{active}, or
876\code{none} may be interpreted as the above literals, instead.
877\end{itemize}
878\end{description}
879
880
Fred Drakec66ff202001-11-16 01:05:27 +0000881\section{\module{Tix} ---
882 Extension widgets for Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000883
884\declaremodule{standard}{Tix}
885\modulesynopsis{Tk Extension Widgets for Tkinter}
886\sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
887
Fred Drakec66ff202001-11-16 01:05:27 +0000888\index{Tix}
889
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000890The \module{Tix} (Tk Interface Extension) module provides an
891additional rich set of widgets. Although the standard Tk library has
892many useful widgets, they are far from complete. The \module{Tix}
893library provides most of the commonly needed widgets that are missing
894from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
895(a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
896also includes many more widgets that are generally useful in a wide
897range of applications: \class{NoteBook}, \class{FileEntry},
898\class{PanedWindow}, etc; there are more than 40 of them.
899
900With all these new widgets, you can introduce new interaction
901techniques into applications, creating more useful and more intuitive
902user interfaces. You can design your application by choosing the most
903appropriate widgets to match the special needs of your application and
904users.
905
906\begin{seealso}
907\seetitle[http://tix.sourceforge.net/]
908 {Tix Homepage}
909 {See the home page for \module{Tix}.}
910\seetitle[http://tix.sourceforge.net/dist/current/man/]
911 {Tix Man Pages}
912 {On-line version of the man pages and reference material.}
913\seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html]
914 {Tix Programming Guide}
915 {On-line version of the programmer's reference material.}
916\seetitle[http://tix.sourceforge.net/Tide/]
917 {Tix Development Applications}
918 {Tix applications for development of Tix and Tkinter programs.
919 Tide applications work under Tk or Tkinter, and include
920 \program{TixInspect}, an inspector to remotely modify and
921 debug Tix/Tk/Tkinter applications.}
922\end{seealso}
923
924
925\subsection{Using Tix}
926
Fred Drake666ca802001-11-16 06:02:55 +0000927\begin{classdesc}{Tix}{screenName\optional{, baseName\optional{, className}}}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000928 Toplevel widget of Tix which represents mostly the main window
929 of an application. It has an associated Tcl interpreter.
930
Fred Drake666ca802001-11-16 06:02:55 +0000931Classes in the \refmodule{Tix} module subclasses the classes in the
932\refmodule{Tkinter} module. The former imports the latter, so to use
933\refmodule{Tix} with Tkinter, all you need to do is to import one
934module. In general, you can just import \refmodule{Tix}, and replace
935the toplevel call to \class{Tkinter.Tk} with \class{Tix.Tk}:
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000936\begin{verbatim}
937import Tix
938from Tkconstants import *
939root = Tix.Tk()
940\end{verbatim}
941\end{classdesc}
942
943To use \refmodule{Tix}, you must have the \refmodule{Tix} widgets installed,
944usually alongside your installation of the Tk widgets.
945To test your installation, try the following:
946\begin{verbatim}
947import Tix
948root = Tix.Tk()
949root.tk.eval('package require Tix')
950\end{verbatim}
951
952If this fails, you have a Tk installation problem which must be
953resolved before proceeding. Use the environment variable \envvar{TIX_LIBRARY}
954to point to the installed \refmodule{Tix} library directory, and
955make sure you have the dynamic object library (\file{tix8183.dll} or
956\file{libtix8183.so}) in the same directory that contains your Tk
957dynamic object library (\file{tk8183.dll} or \file{libtk8183.so}). The
958directory with the dynamic object library should also have a file
959called \file{pkgIndex.tcl} (case sensitive), which contains the line:
960
961\begin{verbatim}
962package ifneeded Tix 8.1 [list load "[file join $dir tix8183.dll]" Tix]
963\end{verbatim} % $ <-- bow to font-lock
964
965
966\subsection{Tix Widgets}
967
968\ulink{Tix}
969{http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm}
970introduces over 40 widget classes to the \refmodule{Tkinter}
971repertoire. There is a demo of all the \refmodule{Tix} widgets in the
972\file{Demo/tix} directory of the standard distribution.
973
974
975% The Python sample code is still being added to Python, hence commented out
976
977
978\subsubsection{Basic Widgets}
979
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000980\begin{classdesc}{Balloon}{}
981A \ulink{Balloon}
Fred Drakec66ff202001-11-16 01:05:27 +0000982{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm}
983that pops up over a widget to provide help. When the user moves the
984cursor inside a widget to which a Balloon widget has been bound, a
985small pop-up window with a descriptive message will be shown on the
986screen.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000987\end{classdesc}
988
Fred Drakec66ff202001-11-16 01:05:27 +0000989% Python Demo of:
990% \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000991
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000992\begin{classdesc}{ButtonBox}{}
993The \ulink{ButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +0000994{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm}
995widget creates a box of buttons, such as is commonly used for \code{Ok
996Cancel}.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000997\end{classdesc}
998
Fred Drakec66ff202001-11-16 01:05:27 +0000999% Python Demo of:
1000% \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001001
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001002\begin{classdesc}{ComboBox}{}
1003The \ulink{ComboBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001004{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm}
1005widget is similar to the combo box control in MS Windows. The user can
1006select a choice by either typing in the entry subwdget or selecting
1007from the listbox subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001008\end{classdesc}
1009
Fred Drakec66ff202001-11-16 01:05:27 +00001010% Python Demo of:
1011% \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001012
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001013\begin{classdesc}{Control}{}
1014The \ulink{Control}
Fred Drakec66ff202001-11-16 01:05:27 +00001015{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm}
1016widget is also known as the \class{SpinBox} widget. The user can
1017adjust the value by pressing the two arrow buttons or by entering the
1018value directly into the entry. The new value will be checked against
1019the user-defined upper and lower limits.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001020\end{classdesc}
1021
Fred Drakec66ff202001-11-16 01:05:27 +00001022% Python Demo of:
1023% \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001024
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001025\begin{classdesc}{LabelEntry}{}
1026The \ulink{LabelEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001027{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm}
1028widget packages an entry widget and a label into one mega widget. It
1029can be used be used to simplify the creation of ``entry-form'' type of
1030interface.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001031\end{classdesc}
1032
1033% Python Demo of:
1034% \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
1035
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001036\begin{classdesc}{LabelFrame}{}
1037The \ulink{LabelFrame}
Fred Drakec66ff202001-11-16 01:05:27 +00001038{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm}
1039widget packages a frame widget and a label into one mega widget. To
1040create widgets inside a LabelFrame widget, one creates the new widgets
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001041relative to the \member{frame} subwidget and manage them inside the
1042\member{frame} subwidget.
1043\end{classdesc}
1044
1045% Python Demo of:
1046% \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
1047
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001048\begin{classdesc}{Meter}{}
1049The \ulink{Meter}
Fred Drakec66ff202001-11-16 01:05:27 +00001050{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm}
1051widget can be used to show the progress of a background job which may
1052take a long time to execute.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001053\end{classdesc}
1054
1055% Python Demo of:
1056% \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
1057
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001058\begin{classdesc}{OptionMenu}{}
1059The \ulink{OptionMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001060{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm}
1061creates a menu button of options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001062\end{classdesc}
1063
Fred Drakec66ff202001-11-16 01:05:27 +00001064% Python Demo of:
1065% \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001066
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001067\begin{classdesc}{PopupMenu}{}
1068The \ulink{PopupMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001069{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm}
1070widget can be used as a replacement of the \code{tk_popup}
1071command. The advantage of the \refmodule{Tix} \class{PopupMenu} widget
1072is it requires less application code to manipulate.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001073\end{classdesc}
1074
Fred Drakec66ff202001-11-16 01:05:27 +00001075% Python Demo of:
1076% \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001077
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001078\begin{classdesc}{Select}{}
1079The \ulink{Select}
Fred Drakec66ff202001-11-16 01:05:27 +00001080{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm}
1081widget is a container of button subwidgets. It can be used to provide
1082radio-box or check-box style of selection options for the user.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001083\end{classdesc}
1084
Fred Drakec66ff202001-11-16 01:05:27 +00001085% Python Demo of:
1086% \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001087
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001088\begin{classdesc}{StdButtonBox}{}
1089The \ulink{StdButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001090{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm}
1091widget is a group of standard buttons for Motif-like dialog boxes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001092\end{classdesc}
1093
Fred Drakec66ff202001-11-16 01:05:27 +00001094% Python Demo of:
1095% \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001096
1097
1098\subsubsection{File Selectors}
1099
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001100\begin{classdesc}{DirList}{}
1101The \ulink{DirList}
1102{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm} widget
1103displays a list view of a directory, its previous directories and its
1104sub-directories. The user can choose one of the directories displayed
1105in the list or change to another directory.
1106\end{classdesc}
1107
Fred Drakec66ff202001-11-16 01:05:27 +00001108% Python Demo of:
1109% \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001110
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001111\begin{classdesc}{DirTree}{}
1112The \ulink{DirTree}
Fred Drakec66ff202001-11-16 01:05:27 +00001113{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm}
1114widget displays a tree view of a directory, its previous directories
1115and its sub-directories. The user can choose one of the directories
1116displayed in the list or change to another directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001117\end{classdesc}
1118
Fred Drakec66ff202001-11-16 01:05:27 +00001119% Python Demo of:
1120% \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001121
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001122\begin{classdesc}{DirSelectDialog}{}
1123The \ulink{DirSelectDialog}
Fred Drakec66ff202001-11-16 01:05:27 +00001124{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm}
1125widget presents the directories in the file system in a dialog
1126window. The user can use this dialog window to navigate through the
1127file system to select the desired directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001128\end{classdesc}
1129
Fred Drakec66ff202001-11-16 01:05:27 +00001130% Python Demo of:
1131% \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001132
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001133\begin{classdesc}{DirSelectBox}{}
1134The \class{DirSelectBox} is similar
1135to the standard Motif(TM) directory-selection box. It is generally used for
1136the user to choose a directory. DirSelectBox stores the directories mostly
1137recently selected into a ComboBox widget so that they can be quickly
1138selected again.
1139\end{classdesc}
1140
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001141\begin{classdesc}{ExFileSelectBox}{}
1142The \ulink{ExFileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001143{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm}
1144widget is usually embedded in a tixExFileSelectDialog widget. It
1145provides an convenient method for the user to select files. The style
1146of the \class{ExFileSelectBox} widget is very similar to the standard
1147file dialog on MS Windows 3.1.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001148\end{classdesc}
1149
Fred Drakec66ff202001-11-16 01:05:27 +00001150% Python Demo of:
1151%\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001152
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001153\begin{classdesc}{FileSelectBox}{}
1154The \ulink{FileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001155{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm}
1156is similar to the standard Motif(TM) file-selection box. It is
1157generally used for the user to choose a file. FileSelectBox stores the
1158files mostly recently selected into a \class{ComboBox} widget so that
1159they can be quickly selected again.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001160\end{classdesc}
1161
Fred Drakec66ff202001-11-16 01:05:27 +00001162% Python Demo of:
1163% \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001164
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001165\begin{classdesc}{FileEntry}{}
1166The \ulink{FileEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001167{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm}
1168widget can be used to input a filename. The user can type in the
1169filename manually. Alternatively, the user can press the button widget
1170that sits next to the entry, which will bring up a file selection
1171dialog.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001172\end{classdesc}
1173
Fred Drakec66ff202001-11-16 01:05:27 +00001174% Python Demo of:
1175% \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001176
1177
1178\subsubsection{Hierachical ListBox}
1179
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001180\begin{classdesc}{HList}{}
1181The \ulink{HList}
Fred Drakec66ff202001-11-16 01:05:27 +00001182{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm}
1183widget can be used to display any data that have a hierarchical
1184structure, for example, file system directory trees. The list entries
1185are indented and connected by branch lines according to their places
1186in the hierachy.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001187\end{classdesc}
1188
Fred Drakec66ff202001-11-16 01:05:27 +00001189% Python Demo of:
1190% \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001191
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001192\begin{classdesc}{CheckList}{}
1193The \ulink{CheckList}
Fred Drakec66ff202001-11-16 01:05:27 +00001194{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm}
1195widget displays a list of items to be selected by the user. CheckList
1196acts similarly to the Tk checkbutton or radiobutton widgets, except it
1197is capable of handling many more items than checkbuttons or
1198radiobuttons.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001199\end{classdesc}
1200
Fred Drakec66ff202001-11-16 01:05:27 +00001201% Python Demo of:
1202% \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
1203% Python Demo of:
1204% \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
1205% Python Demo of:
1206% \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001207
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001208\begin{classdesc}{Tree}{}
1209The \ulink{Tree}
Fred Drakec66ff202001-11-16 01:05:27 +00001210{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm}
1211widget can be used to display hierachical data in a tree form. The
1212user can adjust the view of the tree by opening or closing parts of
1213the tree.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001214\end{classdesc}
1215
Fred Drakec66ff202001-11-16 01:05:27 +00001216% Python Demo of:
1217% \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001218
Fred Drakec66ff202001-11-16 01:05:27 +00001219% Python Demo of:
1220% \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001221
1222
1223\subsubsection{Tabular ListBox}
1224
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001225\begin{classdesc}{TList}{}
1226The \ulink{TList}
Fred Drakec66ff202001-11-16 01:05:27 +00001227{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm}
1228widget can be used to display data in a tabular format. The list
1229entries of a \class{TList} widget are similar to the entries in the Tk
1230listbox widget. The main differences are (1) the \class{TList} widget
1231can display the list entries in a two dimensional format and (2) you
1232can use graphical images as well as multiple colors and fonts for the
1233list entries.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001234\end{classdesc}
1235
Fred Drakec66ff202001-11-16 01:05:27 +00001236% Python Demo of:
1237% \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
1238% Python Demo of:
1239% \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001240
1241% Grid has yet to be added to Python
1242% \subsubsection{Grid Widget}
Fred Drakec66ff202001-11-16 01:05:27 +00001243% Python Demo of:
1244% \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
1245% Python Demo of:
1246% \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
1247% Python Demo of:
1248% \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001249
1250
1251\subsubsection{Manager Widgets}
1252
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001253\begin{classdesc}{PanedWindow}{}
1254The \ulink{PanedWindow}
Fred Drakec66ff202001-11-16 01:05:27 +00001255{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm}
1256widget allows the user to interactively manipulate the sizes of
1257several panes. The panes can be arranged either vertically or
1258horizontally. The user changes the sizes of the panes by dragging the
1259resize handle between two panes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001260\end{classdesc}
1261
Fred Drakec66ff202001-11-16 01:05:27 +00001262% Python Demo of:
1263% \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001264
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001265\begin{classdesc}{ListNoteBook}{}
1266The \ulink{ListNoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001267{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm}
1268widget is very similar to the \class{TixNoteBook} widget: it can be
1269used to display many windows in a limited space using a notebook
1270metaphor. The notebook is divided into a stack of pages (windows). At
1271one time only one of these pages can be shown. The user can navigate
1272through these pages by choosing the name of the desired page in the
1273\member{hlist} subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001274\end{classdesc}
1275
Fred Drakec66ff202001-11-16 01:05:27 +00001276% Python Demo of:
1277% \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001278
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001279\begin{classdesc}{NoteBook}{}
1280The \ulink{NoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001281{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm}
1282widget can be used to display many windows in a limited space using a
1283notebook metaphor. The notebook is divided into a stack of pages. At
1284one time only one of these pages can be shown. The user can navigate
1285through these pages by choosing the visual ``tabs'' at the top of the
1286NoteBook widget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001287\end{classdesc}
1288
Fred Drakec66ff202001-11-16 01:05:27 +00001289% Python Demo of:
1290% \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001291
1292
1293% \subsubsection{Scrolled Widgets}
Fred Drakec66ff202001-11-16 01:05:27 +00001294% Python Demo of:
1295% \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
1296% Python Demo of:
1297% \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
1298% Python Demo of:
1299% \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
1300% Python Demo of:
1301% \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001302
1303
1304\subsubsection{Image Types}
1305
1306The \refmodule{Tix} module adds:
1307\begin{itemize}
1308\item
1309\ulink{pixmap}
Fred Drake666ca802001-11-16 06:02:55 +00001310{http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm}
1311capabilities to all \refmodule{Tix} and \refmodule{Tkinter} widgets to
1312create color images from XPM files.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001313
1314% Python Demo of: \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
1315
1316% Python Demo of: \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
1317
1318\item
1319\ulink{Compound}
Fred Drake666ca802001-11-16 06:02:55 +00001320{http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html}
1321image types can be used to create images that consists of multiple
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001322horizontal lines; each line is composed of a series of items (texts,
1323bitmaps, images or spaces) arranged from left to right. For example, a
1324compound image can be used to display a bitmap and a text string
1325simutaneously in a Tk \class{Button} widget.
1326
Fred Drake666ca802001-11-16 06:02:55 +00001327% Python Demo of:
1328% \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001329
Fred Drake666ca802001-11-16 06:02:55 +00001330% Python Demo of:
1331% \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001332
Fred Drake666ca802001-11-16 06:02:55 +00001333% Python Demo of:
1334% \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001335
Fred Drake666ca802001-11-16 06:02:55 +00001336% Python Demo of:
1337% \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001338\end{itemize}
1339
1340
1341\subsubsection{Miscellaneous Widgets}
1342
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001343\begin{classdesc}{InputOnly}{}
1344The \ulink{InputOnly}
Fred Drake666ca802001-11-16 06:02:55 +00001345{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
1346widgets are to accept inputs from the user, which can be done with the
1347\code{bind} command (\UNIX{} only).
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001348\end{classdesc}
1349
1350\subsubsection{Form Geometry Manager}
1351
1352In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
Fred Drake666ca802001-11-16 06:02:55 +00001353
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001354\begin{classdesc}{Form}{}
1355The \ulink{Form}
Fred Drake666ca802001-11-16 06:02:55 +00001356{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
1357geometry manager based on attachment rules for all Tk widgets.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001358\end{classdesc}
1359
1360
1361%begin{latexonly}
1362%\subsection{Tix Class Structure}
1363%
1364%\begin{figure}[hbtp]
1365%\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
1366%\vspace{.5cm}
1367%\caption{The Class Hierarchy of Tix Widgets}
1368%\end{figure}
1369%end{latexonly}
1370
Fred Drake44b6f842001-11-29 21:09:08 +00001371\subsection{Tix Commands}
1372
1373\begin{classdesc}{tixCommand}{}
1374The \ulink{tix commands}
1375{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
1376provide access to miscellaneous elements of \refmodule{Tix}'s internal
1377state and the \refmodule{Tix} application context. Most of the information
1378manipulated by these methods pertains to the application as a whole,
1379or to a screen or display, rather than to a particular window.
1380
1381To view the current settings, the common usage is:
1382\begin{verbatim}
1383import Tix
1384root = Tix.Tk()
1385print root.tix_configure()
1386\end{verbatim}
1387\end{classdesc}
1388
1389\begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
1390Query or modify the configuration options of the Tix application
1391context. If no option is specified, returns a dictionary all of the
1392available options. If option is specified with no value, then the
1393method returns a list describing the one named option (this list will
1394be identical to the corresponding sublist of the value returned if no
1395option is specified). If one or more option-value pairs are
1396specified, then the method modifies the given option(s) to have the
1397given value(s); in this case the method returns an empty string.
1398Option may be any of the configuration options.
1399\end{methoddesc}
1400
1401\begin{methoddesc}{tix_cget}{option}
1402Returns the current value of the configuration option given by
1403\var{option}. Option may be any of the configuration options.
1404\end{methoddesc}
1405
1406\begin{methoddesc}{tix_getbitmap}{name}
1407Locates a bitmap file of the name \code{name.xpm} or \code{name} in
1408one of the bitmap directories (see the \method{tix_addbitmapdir()}
1409method). By using \method{tix_getbitmap()}, you can avoid hard
1410coding the pathnames of the bitmap files in your application. When
1411successful, it returns the complete pathname of the bitmap file,
1412prefixed with the character \samp{@}. The returned value can be used to
1413configure the \code{bitmap} option of the Tk and Tix widgets.
1414\end{methoddesc}
1415
1416\begin{methoddesc}{tix_addbitmapdir}{directory}
1417Tix maintains a list of directories under which the
1418\method{tix_getimage()} and \method{tix_getbitmap()} methods will
1419search for image files. The standard bitmap directory is
1420\file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
1421adds \var{directory} into this list. By using this method, the image
1422files of an applications can also be located using the
1423\method{tix_getimage()} or \method{tix_getbitmap()} method.
1424\end{methoddesc}
1425
1426\begin{methoddesc}{tix_filedialog}{\optional{dlgclass}}
1427Returns the file selection dialog that may be shared among different
1428calls from this application. This method will create a file selection
1429dialog widget when it is called the first time. This dialog will be
1430returned by all subsequent calls to \method{tix_filedialog()}. An
1431optional dlgclass parameter can be passed as a string to specified
1432what type of file selection dialog widget is desired. Possible
1433options are \code{tix}, \code{FileSelectDialog} or
1434\code{tixExFileSelectDialog}.
1435\end{methoddesc}
1436
1437
1438\begin{methoddesc}{tix_getimage}{self, name}
1439Locates an image file of the name \file{name.xpm}, \file{name.xbm} or
1440\file{name.ppm} in one of the bitmap directories (see the
1441\method{tix_addbitmapdir()} method above). If more than one file with
1442the same name (but different extensions) exist, then the image type is
1443chosen according to the depth of the X display: xbm images are chosen
1444on monochrome displays and color images are chosen on color
1445displays. By using \method{tix_getimage()}, you can avoid hard coding
1446the pathnames of the image files in your application. When successful,
1447this method returns the name of the newly created image, which can be
1448used to configure the \code{image} option of the Tk and Tix widgets.
1449\end{methoddesc}
1450
1451\begin{methoddesc}{tix_option_get}{name}
1452Gets the options manitained by the Tix scheme mechanism.
1453\end{methoddesc}
1454
1455\begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
1456 newScmPrio}}
1457Resets the scheme and fontset of the Tix application to
1458\var{newScheme} and \var{newFontSet}, respectively. This affects only
1459those widgets created after this call. Therefore, it is best to call
1460the resetoptions method before the creation of any widgets in a Tix
1461application.
1462
1463The optional parameter \var{newScmPrio} can be given to reset the
1464priority level of the Tk options set by the Tix schemes.
1465
1466Because of the way Tk handles the X option database, after Tix has
1467been has imported and inited, it is not possible to reset the color
1468schemes and font sets using the \method{tix_config()} method.
1469Instead, the \method{tix_resetoptions()} method must be used.
1470\end{methoddesc}
1471
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001472
Fred Drakec66ff202001-11-16 01:05:27 +00001473\input{libturtle}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001474
1475
1476\section{Idle \label{idle}}
1477
1478%\declaremodule{standard}{idle}
1479%\modulesynopsis{A Python Integrated Developement Environment}
1480\moduleauthor{Guido van Rossum}{guido@Python.org}
1481
1482Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
1483\index{Idle}
1484\index{Python Editor}
1485\index{Integrated Developement Environment}
1486
1487
1488IDLE has the following features:
1489
1490\begin{itemize}
1491\item coded in 100\% pure Python, using the \refmodule{Tkinter} GUI toolkit
1492
1493\item cross-platform: works on Windows and \UNIX{} (on Mac OS, there are
1494currently problems with Tcl/Tk)
1495
1496\item multi-window text editor with multiple undo, Python colorizing
1497and many other features, e.g. smart indent and call tips
1498
1499\item Python shell window (a.k.a. interactive interpreter)
1500
1501\item debugger (not complete, but you can set breakpoints, view and step)
1502\end{itemize}
1503
1504
1505\subsection{Menus}
1506
1507\subsubsection{File menu}
1508
1509\begin{description}
1510\item[New window] create a new editing window
1511\item[Open...] open an existing file
1512\item[Open module...] open an existing module (searches sys.path)
1513\item[Class browser] show classes and methods in current file
1514\item[Path browser] show sys.path directories, modules, classes and methods
1515\end{description}
1516\index{Class browser}
1517\index{Path browser}
1518
1519\begin{description}
1520\item[Save] save current window to the associated file (unsaved
1521windows have a * before and after the window title)
1522
1523\item[Save As...] save current window to new file, which becomes
1524the associated file
1525\item[Save Copy As...] save current window to different file
1526without changing the associated file
1527\end{description}
1528
1529\begin{description}
1530\item[Close] close current window (asks to save if unsaved)
1531\item[Exit] close all windows and quit IDLE (asks to save if unsaved)
1532\end{description}
1533
1534
1535\subsubsection{Edit menu}
1536
1537\begin{description}
1538\item[Undo] Undo last change to current window (max 1000 changes)
1539\item[Redo] Redo last undone change to current window
1540\end{description}
1541
1542\begin{description}
1543\item[Cut] Copy selection into system-wide clipboard; then delete selection
1544\item[Copy] Copy selection into system-wide clipboard
1545\item[Paste] Insert system-wide clipboard into window
1546\item[Select All] Select the entire contents of the edit buffer
1547\end{description}
1548
1549\begin{description}
1550\item[Find...] Open a search dialog box with many options
1551\item[Find again] Repeat last search
1552\item[Find selection] Search for the string in the selection
1553\item[Find in Files...] Open a search dialog box for searching files
1554\item[Replace...] Open a search-and-replace dialog box
1555\item[Go to line] Ask for a line number and show that line
1556\end{description}
1557
1558\begin{description}
1559\item[Indent region] Shift selected lines right 4 spaces
1560\item[Dedent region] Shift selected lines left 4 spaces
1561\item[Comment out region] Insert \#\# in front of selected lines
1562\item[Uncomment region] Remove leading \# or \#\# from selected lines
1563\item[Tabify region] Turns \emph{leading} stretches of spaces into tabs
1564\item[Untabify region] Turn \emph{all} tabs into the right number of spaces
1565\item[Expand word] Expand the word you have typed to match another
1566 word in the same buffer; repeat to get a different expansion
1567\item[Format Paragraph] Reformat the current blank-line-separated paragraph
1568\end{description}
1569
1570\begin{description}
1571\item[Import module] Import or reload the current module
1572\item[Run script] Execute the current file in the __main__ namespace
1573\end{description}
1574
1575\index{Import module}
1576\index{Run script}
1577
1578
1579\subsubsection{Windows menu}
1580
1581\begin{description}
1582\item[Zoom Height] toggles the window between normal size (24x80)
1583 and maximum height.
1584\end{description}
1585
1586The rest of this menu lists the names of all open windows; select one
1587to bring it to the foreground (deiconifying it if necessary).
1588
1589
1590\subsubsection{Debug menu (in the Python Shell window only)}
1591
1592\begin{description}
1593\item[Go to file/line] look around the insert point for a filename
1594 and linenumber, open the file, and show the line.
1595\item[Open stack viewer] show the stack traceback of the last exception
1596\item[Debugger toggle] Run commands in the shell under the debugger
1597\item[JIT Stack viewer toggle] Open stack viewer on traceback
1598\end{description}
1599
1600\index{stack viewer}
1601\index{debugger}
1602
1603
1604\subsection{Basic editing and navigation}
1605
1606\begin{itemize}
1607\item \kbd{Backspace} deletes to the left; \kbd{Del} deletes to the right
1608\item Arrow keys and \kbd{Page Up}/\kbd{Page Down} to move around
1609\item \kbd{Home}/\kbd{End} go to begin/end of line
1610\item \kbd{C-Home}/\kbd{C-End} go to begin/end of file
1611\item Some \program{Emacs} bindings may also work, including \kbd{C-B},
1612 \kbd{C-P}, \kbd{C-A}, \kbd{C-E}, \kbd{C-D}, \kbd{C-L}
1613\end{itemize}
1614
1615
1616\subsubsection{Automatic indentation}
1617
1618After a block-opening statement, the next line is indented by 4 spaces
1619(in the Python Shell window by one tab). After certain keywords
1620(break, return etc.) the next line is dedented. In leading
1621indentation, \kbd{Backspace} deletes up to 4 spaces if they are there.
1622\kbd{Tab} inserts 1-4 spaces (in the Python Shell window one tab).
1623See also the indent/dedent region commands in the edit menu.
1624
1625
1626\subsubsection{Python Shell window}
1627
1628\begin{itemize}
1629\item \kbd{C-C} interrupts executing command
1630\item \kbd{C-D} sends end-of-file; closes window if typed at
1631a \samp{>>>~} prompt
1632\end{itemize}
1633
1634\begin{itemize}
Fred Drake666ca802001-11-16 06:02:55 +00001635\item \kbd{Alt-p} retrieves previous command matching what you have typed
1636\item \kbd{Alt-n} retrieves next
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001637\item \kbd{Return} while on any previous command retrieves that command
Fred Drake666ca802001-11-16 06:02:55 +00001638\item \kbd{Alt-/} (Expand word) is also useful here
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001639\end{itemize}
1640
1641\index{indentation}
1642
1643
1644\subsection{Syntax colors}
1645
1646The coloring is applied in a background ``thread,'' so you may
1647occasionally see uncolorized text. To change the color
1648scheme, edit the \code{[Colors]} section in \file{config.txt}.
1649
1650\begin{description}
1651\item[Python syntax colors:]
1652
1653\begin{description}
1654\item[Keywords] orange
1655\item[Strings ] green
1656\item[Comments] red
1657\item[Definitions] blue
1658\end{description}
1659
1660\item[Shell colors:]
1661\begin{description}
1662\item[Console output] brown
1663\item[stdout] blue
1664\item[stderr] dark green
1665\item[stdin] black
1666\end{description}
1667\end{description}
1668
1669
1670\subsubsection{Command line usage}
1671
1672\begin{verbatim}
1673idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
1674
1675-c command run this command
1676-d enable debugger
1677-e edit mode; arguments are files to be edited
1678-s run $IDLESTARTUP or $PYTHONSTARTUP first
1679-t title set title of shell window
1680\end{verbatim}
1681
1682If there are arguments:
1683
1684\begin{enumerate}
1685\item If \programopt{-e} is used, arguments are files opened for
1686 editing and \code{sys.argv} reflects the arguments passed to
1687 IDLE itself.
1688
1689\item Otherwise, if \programopt{-c} is used, all arguments are
1690 placed in \code{sys.argv[1:...]}, with \code{sys.argv[0]} set
1691 to \code{'-c'}.
1692
1693\item Otherwise, if neither \programopt{-e} nor \programopt{-c} is
1694 used, the first argument is a script which is executed with
1695 the remaining arguments in \code{sys.argv[1:...]} and
1696 \code{sys.argv[0]} set to the script name. If the script name
1697 is '-', no script is executed but an interactive Python
1698 session is started; the arguments are still available in
1699 \code{sys.argv}.
1700\end{enumerate}
Fred Drakec66ff202001-11-16 01:05:27 +00001701
1702
1703\section{Other Graphical User Interface Packages
1704 \label{other-gui-packages}}
1705
1706
1707There are an number of extension widget sets to \refmodule{Tkinter}.
1708
Fred Drake10cd3152001-11-30 18:17:24 +00001709\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001710\seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
1711toolkit for building high-level compound widgets in Python using the
1712\refmodule{Tkinter} module. It consists of a set of base classes and
1713a library of flexible and extensible megawidgets built on this
1714foundation. These megawidgets include notebooks, comboboxes, selection
1715widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1716with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1717and vector commands are be available.
1718
1719The initial ideas for Pmw were taken from the Tk \code{itcl}
1720extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
1721Widgets]} by Mark Ulferts. Several of the megawidgets are direct
1722translations from the itcl to Python. It offers most of the range of
1723widgets that \code{[incr Widgets]} does, and is almost as complete as
1724Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
1725}
1726\seetitle[http://tkinter.effbot.org]{Tkinter3000}{
1727is a Widget Construction Kit that allows you to write new Tkinter
1728widgets in Python using Mixins. It is built on top of Tkinter,
1729and does not offer the extended range of widgets that \refmodule{Tix} does,
1730but does allow a form of building mega-widgets. The project is
1731still in the early stages.
1732}
Fred Drake10cd3152001-11-30 18:17:24 +00001733\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001734
1735
Fred Drake666ca802001-11-16 06:02:55 +00001736Tk is not the only GUI for Python, but is however the
Fred Drakec66ff202001-11-16 01:05:27 +00001737most commonly used one.
1738
Fred Drake10cd3152001-11-30 18:17:24 +00001739\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001740\seetitle[http://www.wxwindows.org]{wxWindows}{
1741is a GUI toolkit that combines the most attractive attributes of Qt,
1742Tk, Motif, and GTK+ in one powerful and efficient package. It is
Fred Drakec37b65e2001-11-28 07:26:15 +00001743implemented in \Cpp. wxWindows supports two flavors of \UNIX{}
Fred Drakec66ff202001-11-16 01:05:27 +00001744implementation: GTK+ and Motif, and under Windows, it has a standard
1745Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1746widgets. There is a Python class wrapper, independent of Tkinter.
1747
1748wxWindows is much richer in widgets than \refmodule{Tkinter}, with its
1749help system, sophisticated HTML and image viewers, and other
1750specialized widgets, extensive documentation, and printing capabilities.
1751}
1752\seetitle[http://www.thekompany.com]{PyKDE}{
1753PyKDE is a SIP wrapped interface to the Qt toolkit.
1754The Qt \Cpp{} toolkit lies at the heart of the KDE desktop, and the
1755Qt toolkit allows very tight integration with KDE, and also Windows
1756portability. SIP is a tool for generating bindings for \Cpp{} libraries
1757as Python classes, and is specifically designed for Python.
1758}
1759\seetitle[http://fxpy.sourceforge.net/]{FXPy}{
1760is a Python extension module which provides an interface to the
1761\citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
1762FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
1763easily and effectively. It offers a wide, and growing, collection of
1764Controls, and provides state of the art facilities such as drag and
1765drop, selection, as well as OpenGL widgets for 3D graphical
1766manipulation. FOX also implements icons, images, and user-convenience
1767features such as status line help, and tooltips.
1768
1769Even though FOX offers a large collection of controls already, FOX
1770leverages \Cpp{} to allow programmers to easily build additional Controls
1771and GUI elements, simply by taking existing controls, and creating a
1772derived class which simply adds or redefines the desired behavior.
1773}
1774\seetitle[http://www.daa.com.au/\~james/pygtk/]{PyGTK}{
1775is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
1776It provides an object oriented interface that is slightly higher
1777level than the C one. It automatically does all the type casting and
1778reference counting that you would have to do normally with the C
1779API. There are also \ulink{bindings}{http://www.daa.com.au/\~james/gnome/}
1780to \ulink{GNOME}{http://www.gnome.org}, and a
1781\ulink{tutorial}
1782{http://laguna.fmedic.unam.mx/\~daniel/pygtutorial/pygtutorial/index.html}
1783is available.
1784}
Fred Drake10cd3152001-11-30 18:17:24 +00001785\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001786
1787% XXX Reference URLs that compare the different UI packages