blob: 55f822ffd33b4aa2c47e615e65008b5eae80817f [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
Fred Drake691fb552002-09-10 21:59:17 +000041interface to the Tk GUI toolkit. Both Tk and \module{Tkinter} are
42available on most \UNIX{} platforms, as well as on Windows and
43Macintosh systems. (Tk itself is not part of Python; it is maintained
44at ActiveState.)
Fred Drake7cf4e5b2001-11-15 17:22:04 +000045
46\begin{seealso}
47\seetitle[http://www.python.org/topics/tkinter/]
48 {Python Tkinter Resources}
49 {The Python Tkinter Topic Guide provides a great
50 deal of information on using Tk from Python and links to
51 other sources of information on Tk.}
52
53\seetitle[http://www.pythonware.com/library/an-introduction-to-tkinter.htm]
54 {An Introduction to Tkinter}
55 {Fredrik Lundh's on-line reference material.}
56
57\seetitle[http://www.nmt.edu/tcc/help/pubs/lang.html]
58 {Tkinter reference: a GUI for Python}
59 {On-line reference material.}
60
61\seetitle[http://jtkinter.sourceforge.net]
62 {Tkinter for JPython}
63 {The Jython interface to Tkinter.}
64
65\seetitle[http://www.amazon.com/exec/obidos/ASIN/1884777813]
66 {Python and Tkinter Programming}
67 {The book by John Grayson (ISBN 1-884777-81-3).}
68\end{seealso}
69
70
71\subsection{Tkinter Modules}
72
Fred Drake666ca802001-11-16 06:02:55 +000073Most of the time, the \refmodule{Tkinter} module is all you really
74need, but a number of additional modules are available as well. The
75Tk interface is located in a binary module named \module{_tkinter}.
76This module contains the low-level interface to Tk, and should never
77be used directly by application programmers. It is usually a shared
78library (or DLL), but might in some cases be statically linked with
79the Python interpreter.
Fred Drake7cf4e5b2001-11-15 17:22:04 +000080
81In addition to the Tk interface module, \refmodule{Tkinter} includes a
82number of Python modules. The two most important modules are the
83\refmodule{Tkinter} module itself, and a module called
84\module{Tkconstants}. The former automatically imports the latter, so
85to use Tkinter, all you need to do is to import one module:
86
87\begin{verbatim}
88import Tkinter
89\end{verbatim}
90
91Or, more often:
92
93\begin{verbatim}
94from Tkinter import *
95\end{verbatim}
96
David Aschere2b4b322004-02-18 05:59:53 +000097\begin{classdesc}{Tk}{screenName=None, baseName=None, className='Tk', useTk=1}
Fred Drake7cf4e5b2001-11-15 17:22:04 +000098The \class{Tk} class is instantiated without arguments.
99This creates a toplevel widget of Tk which usually is the main window
100of an appliation. Each instance has its own associated Tcl interpreter.
101% FIXME: The following keyword arguments are currently recognized:
102\end{classdesc}
103
David Aschere2b4b322004-02-18 05:59:53 +0000104\begin{funcdesc}{Tcl}{screenName=None, baseName=None, className='Tk', useTk=0}
105The \function{Tcl} function is a factory function which creates an object
106much like that created by the \class{Tk} class, except that it does not
107initialize the Tk subsystem. This is most often useful when driving the Tcl
108interpreter in an environment where one doesn't want to create extraneous
109toplevel windows, or where one cannot (i.e. Unix/Linux systems without an X
110server). An object created by the \function{Tcl} object can have a Toplevel
111window created (and the Tk subsystem initialized) by calling its
112\method{loadtk} method.
113\end{funcdesc}
114
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000115Other modules that provide Tk support include:
116
117\begin{description}
118% \declaremodule{standard}{Tkconstants}
119% \modulesynopsis{Constants used by Tkinter}
120% FIXME
121
Fred Drake1a763862001-12-03 21:18:30 +0000122\item[\refmodule{ScrolledText}]
123Text widget with a vertical scroll bar built in.
124
Fred Drakec66ff202001-11-16 01:05:27 +0000125\item[\module{tkColorChooser}]
126Dialog to let the user choose a color.
127
128\item[\module{tkCommonDialog}]
Fred Drake04677752001-11-30 19:24:49 +0000129Base class for the dialogs defined in the other modules listed here.
Fred Drakec66ff202001-11-16 01:05:27 +0000130
131\item[\module{tkFileDialog}]
132Common dialogs to allow the user to specify a file to open or save.
133
134\item[\module{tkFont}]
135Utilities to help work with fonts.
136
137\item[\module{tkMessageBox}]
138Access to standard Tk dialog boxes.
139
140\item[\module{tkSimpleDialog}]
141Basic dialogs and convenience functions.
142
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000143\item[\module{Tkdnd}]
144Drag-and-drop support for \refmodule{Tkinter}.
145This is experimental and should become deprecated when it is replaced
146with the Tk DND.
147
148\item[\refmodule{turtle}]
149Turtle graphics in a Tk window.
150
151\end{description}
152
153\subsection{Tkinter Life Preserver}
Fred Drakec66ff202001-11-16 01:05:27 +0000154\sectionauthor{Matt Conway}{}
155% Converted to LaTeX by Mike Clarkson.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000156
157This section is not designed to be an exhaustive tutorial on either
158Tk or Tkinter. Rather, it is intended as a stop gap, providing some
159introductory orientation on the system.
160
161Credits:
162\begin{itemize}
163\item Tkinter was written by Steen Lumholt and Guido van Rossum.
164\item Tk was written by John Ousterhout while at Berkeley.
165\item This Life Preserver was written by Matt Conway at
166the University of Virginia.
167\item The html rendering, and some liberal editing, was
168produced from a FrameMaker version by Ken Manheimer.
169\item Fredrik Lundh elaborated and revised the class interface descriptions,
170to get them current with Tk 4.2.
171\item Mike Clarkson converted the documentation to \LaTeX, and compiled the
172User Interface chapter of the reference manual.
173\end{itemize}
174
175
176\subsubsection{How To Use This Section}
177
178This section is designed in two parts: the first half (roughly) covers
179background material, while the second half can be taken to the
180keyboard as a handy reference.
181
182When trying to answer questions of the form ``how do I do blah'', it
183is often best to find out how to do``blah'' in straight Tk, and then
184convert this back into the corresponding \refmodule{Tkinter} call.
185Python programmers can often guess at the correct Python command by
186looking at the Tk documentation. This means that in order to use
187Tkinter, you will have to know a little bit about Tk. This document
188can't fulfill that role, so the best we can do is point you to the
189best documentation that exists. Here are some hints:
190
191\begin{itemize}
192\item The authors strongly suggest getting a copy of the Tk man
193pages. Specifically, the man pages in the \code{mann} directory are most
194useful. The \code{man3} man pages describe the C interface to the Tk
195library and thus are not especially helpful for script writers.
196
197\item Addison-Wesley publishes a book called \citetitle{Tcl and the
198Tk Toolkit} by John Ousterhout (ISBN 0-201-63337-X) which is a good
199introduction to Tcl and Tk for the novice. The book is not
200exhaustive, and for many details it defers to the man pages.
201
202\item \file{Tkinter.py} is a last resort for most, but can be a good
203place to go when nothing else makes sense.
204\end{itemize}
205
206\begin{seealso}
207\seetitle[http://tcl.activestate.com/]
208 {ActiveState Tcl Home Page}
209 {The Tk/Tcl development is largely taking place at
210 ActiveState.}
211\seetitle[http://www.amazon.com/exec/obidos/ASIN/020163337X]
212 {Tcl and the Tk Toolkit}
213 {The book by John Ousterhout, the inventor of Tcl .}
214\seetitle[http://www.amazon.com/exec/obidos/ASIN/0130220280]
215 {Practical Programming in Tcl and Tk}
216 {Brent Welch's encyclopedic book.}
217\end{seealso}
218
219
220\subsubsection{A Simple Hello World Program} % HelloWorld.html
221
222%begin{latexonly}
223%\begin{figure}[hbtp]
224%\centerline{\epsfig{file=HelloWorld.gif,width=.9\textwidth}}
225%\vspace{.5cm}
226%\caption{HelloWorld gadget image}
227%\end{figure}
228%See also the hello-world \ulink{notes}{classes/HelloWorld-notes.html} and
229%\ulink{summary}{classes/HelloWorld-summary.html}.
230%end{latexonly}
231
232
233\begin{verbatim}
Fred Drakee5a55512003-05-20 15:21:08 +0000234from Tkinter import *
235
236class Application(Frame):
237 def say_hi(self):
238 print "hi there, everyone!"
239
240 def createWidgets(self):
241 self.QUIT = Button(self)
242 self.QUIT["text"] = "QUIT"
243 self.QUIT["fg"] = "red"
244 self.QUIT["command"] = self.quit
245
246 self.QUIT.pack({"side": "left"})
247
248 self.hi_there = Button(self)
249 self.hi_there["text"] = "Hello",
250 self.hi_there["command"] = self.say_hi
251
252 self.hi_there.pack({"side": "left"})
253
254 def __init__(self, master=None):
255 Frame.__init__(self, master)
256 self.pack()
257 self.createWidgets()
258
259app = Application()
260app.mainloop()
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000261\end{verbatim}
262
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000263
Fred Drakeb22c6722001-12-03 06:12:23 +0000264\subsection{A (Very) Quick Look at Tcl/Tk} % BriefTclTk.html
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000265
266The class hierarchy looks complicated, but in actual practice,
267application programmers almost always refer to the classes at the very
268bottom of the hierarchy.
269
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000270Notes:
271\begin{itemize}
272\item These classes are provided for the purposes of
273organizing certain functions under one namespace. They aren't meant to
274be instantiated independently.
Fred Drakeb22c6722001-12-03 06:12:23 +0000275
276\item The \class{Tk} class is meant to be instantiated only once in
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000277an application. Application programmers need not instantiate one
278explicitly, the system creates one whenever any of the other classes
279are instantiated.
Fred Drakeb22c6722001-12-03 06:12:23 +0000280
281\item The \class{Widget} class is not meant to be instantiated, it
282is meant only for subclassing to make ``real'' widgets (in \Cpp, this
283is called an `abstract class').
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000284\end{itemize}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000285
286To make use of this reference material, there will be times when you
287will need to know how to read short passages of Tk and how to identify
288the various parts of a Tk command.
Fred Drake666ca802001-11-16 06:02:55 +0000289(See section~\ref{tkinter-basic-mapping} for the
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000290\refmodule{Tkinter} equivalents of what's below.)
291
292Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
293just lists of tokens separated by spaces. A Tk widget is just its
294\emph{class}, the \emph{options} that help configure it, and the
295\emph{actions} that make it do useful things.
296
297To make a widget in Tk, the command is always of the form:
298
299\begin{verbatim}
300 classCommand newPathname options
301\end{verbatim}
302
303\begin{description}
304\item[\var{classCommand}]
305denotes which kind of widget to make (a button, a label, a menu...)
306
307\item[\var{newPathname}]
308is the new name for this widget. All names in Tk must be unique. To
309help enforce this, widgets in Tk are named with \emph{pathnames}, just
310like files in a file system. The top level widget, the \emph{root},
311is called \code{.} (period) and children are delimited by more
312periods. For example, \code{.myApp.controlPanel.okButton} might be
313the name of a widget.
314
315\item[\var{options} ]
316configure the widget's appearance and in some cases, its
317behavior. The options come in the form of a list of flags and values.
318Flags are proceeded by a `-', like unix shell command flags, and
319values are put in quotes if they are more than one word.
320\end{description}
321
322For example:
323
324\begin{verbatim}
325 button .fred -fg red -text "hi there"
326 ^ ^ \_____________________/
327 | | |
328 class new options
329 command widget (-opt val -opt val ...)
330\end{verbatim}
331
332Once created, the pathname to the widget becomes a new command. This
333new \var{widget command} is the programmer's handle for getting the new
334widget to perform some \var{action}. In C, you'd express this as
Fred Drakec66ff202001-11-16 01:05:27 +0000335someAction(fred, someOptions), in \Cpp, you would express this as
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000336fred.someAction(someOptions), and in Tk, you say:
337
338\begin{verbatim}
339 .fred someAction someOptions
340\end{verbatim}
341
342Note that the object name, \code{.fred}, starts with a dot.
343
344As you'd expect, the legal values for \var{someAction} will depend on
345the widget's class: \code{.fred disable} works if fred is a
346button (fred gets greyed out), but does not work if fred is a label
347(disabling of labels is not supported in Tk).
348
349The legal values of \var{someOptions} is action dependent. Some
350actions, like \code{disable}, require no arguments, others, like
351a text-entry box's \code{delete} command, would need arguments
352to specify what range of text to delete.
353
354
355\subsection{Mapping Basic Tk into Tkinter
356 \label{tkinter-basic-mapping}}
357
358Class commands in Tk correspond to class constructors in Tkinter.
359
360\begin{verbatim}
361 button .fred =====> fred = Button()
362\end{verbatim}
363
364The master of an object is implicit in the new name given to it at
365creation time. In Tkinter, masters are specified explicitly.
366
367\begin{verbatim}
368 button .panel.fred =====> fred = Button(panel)
369\end{verbatim}
370
371The configuration options in Tk are given in lists of hyphened tags
372followed by values. In Tkinter, options are specified as
373keyword-arguments in the instance constructor, and keyword-args for
374configure calls or as instance indices, in dictionary style, for
Fred Drake666ca802001-11-16 06:02:55 +0000375established instances. See section~\ref{tkinter-setting-options} on
376setting options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000377
378\begin{verbatim}
379 button .fred -fg red =====> fred = Button(panel, fg = "red")
380 .fred configure -fg red =====> fred["fg"] = red
381 OR ==> fred.config(fg = "red")
382\end{verbatim}
383
384In Tk, to perform an action on a widget, use the widget name as a
385command, and follow it with an action name, possibly with arguments
386(options). In Tkinter, you call methods on the class instance to
387invoke actions on the widget. The actions (methods) that a given
388widget can perform are listed in the Tkinter.py module.
389
390\begin{verbatim}
391 .fred invoke =====> fred.invoke()
392\end{verbatim}
393
394To give a widget to the packer (geometry manager), you call pack with
395optional arguments. In Tkinter, the Pack class holds all this
396functionality, and the various forms of the pack command are
397implemented as methods. All widgets in \refmodule{Tkinter} are
398subclassed from the Packer, and so inherit all the packing
399methods. See the \refmodule{Tix} module documentation for additional
400information on the Form geometry manager.
401
402\begin{verbatim}
403 pack .fred -side left =====> fred.pack(side = "left")
404\end{verbatim}
405
406
407\subsection{How Tk and Tkinter are Related} % Relationship.html
408
Fred Drake666ca802001-11-16 06:02:55 +0000409\note{This was derived from a graphical image; the image will be used
410 more directly in a subsequent version of this document.}
411
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000412From the top down:
413\begin{description}
414\item[\b{Your App Here (Python)}]
415A Python application makes a \refmodule{Tkinter} call.
416
417\item[\b{Tkinter (Python Module)}]
418This call (say, for example, creating a button widget), is
419implemented in the \emph{Tkinter} module, which is written in
420Python. This Python function will parse the commands and the
421arguments and convert them into a form that makes them look as if they
422had come from a Tk script instead of a Python script.
423
424\item[\b{tkinter (C)}]
425These commands and their arguments will be passed to a C function
426in the \emph{tkinter} - note the lowercase - extension module.
427
428\item[\b{Tk Widgets} (C and Tcl)]
429This C function is able to make calls into other C modules,
430including the C functions that make up the Tk library. Tk is
431implemented in C and some Tcl. The Tcl part of the Tk widgets is used
432to bind certain default behaviors to widgets, and is executed once at
433the point where the Python \refmodule{Tkinter} module is
434imported. (The user never sees this stage).
435
436\item[\b{Tk (C)}]
437The Tk part of the Tk Widgets implement the final mapping to ...
438
439\item[\b{Xlib (C)}]
440the Xlib library to draw graphics on the screen.
441\end{description}
442
443
444\subsection{Handy Reference}
445
446\subsubsection{Setting Options
447 \label{tkinter-setting-options}}
448
449Options control things like the color and border width of a widget.
450Options can be set in three ways:
451
452\begin{description}
453\item[At object creation time, using keyword arguments]:
454\begin{verbatim}
455fred = Button(self, fg = "red", bg = "blue")
456\end{verbatim}
457\item[After object creation, treating the option name like a dictionary index]:
458\begin{verbatim}
459fred["fg"] = "red"
460fred["bg"] = "blue"
461\end{verbatim}
462\item[Use the config() method to update multiple attrs subesequent to
463object creation]:
464\begin{verbatim}
465fred.config(fg = "red", bg = "blue")
466\end{verbatim}
467\end{description}
468
469For a complete explanation of a given option and its behavior, see the
470Tk man pages for the widget in question.
471
472Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
473OPTIONS" for each widget. The former is a list of options that are
474common to many widgets, the latter are the options that are
475ideosyncratic to that particular widget. The Standard Options are
476documented on the \manpage{options}{3} man page.
477
478No distinction between standard and widget-specific options is made in
479this document. Some options don't apply to some kinds of widgets.
480Whether a given widget responds to a particular option depends on the
481class of the widget; buttons have a \code{command} option, labels do not.
482
483The options supported by a given widget are listed in that widget's
484man page, or can be queried at runtime by calling the
Fred Drakec6a525e2002-07-08 14:42:22 +0000485\method{config()} method without arguments, or by calling the
486\method{keys()} method on that widget. The return value of these
487calls is a dictionary whose key is the name of the option as a string
488(for example, \code{'relief'}) and whose values are 5-tuples.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000489
Fred Drakec6a525e2002-07-08 14:42:22 +0000490Some options, like \code{bg} are synonyms for common options with long
491names (\code{bg} is shorthand for "background"). Passing the
492\code{config()} method the name of a shorthand option will return a
4932-tuple, not 5-tuple. The 2-tuple passed back will contain the name of
494the synonym and the ``real'' option (such as \code{('bg',
495'background')}).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000496
497\begin{tableiii}{c|l|l}{textrm}{Index}{Meaning}{Example}
498 \lineiii{0}{option name} {\code{'relief'}}
499 \lineiii{1}{option name for database lookup} {\code{'relief'}}
500 \lineiii{2}{option class for database lookup} {\code{'Relief'}}
501 \lineiii{3}{default value} {\code{'raised'}}
502 \lineiii{4}{current value} {\code{'groove'}}
503\end{tableiii}
504
505
506Example:
507
508\begin{verbatim}
509>>> print fred.config()
510{'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}
511\end{verbatim}
512
513Of course, the dictionary printed will include all the options
514available and their values. This is meant only as an example.
515
516
517\subsubsection{The Packer} % Packer.html
518\index{packing (widgets)}
519
520The packer is one of Tk's geometry-management mechanisms. See also
521\citetitle[classes/ClassPacker.html]{the Packer class interface}.
522
523Geometry managers are used to specify the relative positioning of the
524positioning of widgets within their container - their mutual
525\emph{master}. In contrast to the more cumbersome \emph{placer}
526(which is used less commonly, and we do not cover here), the packer
527takes qualitative relationship specification - \emph{above}, \emph{to
528the left of}, \emph{filling}, etc - and works everything out to
529determine the exact placement coordinates for you.
530
531The size of any \emph{master} widget is determined by the size of
532the "slave widgets" inside. The packer is used to control where slave
533widgets appear inside the master into which they are packed. You can
534pack widgets into frames, and frames into other frames, in order to
535achieve the kind of layout you desire. Additionally, the arrangement
536is dynamically adjusted to accomodate incremental changes to the
537configuration, once it is packed.
538
539Note that widgets do not appear until they have had their geometry
540specified with a geometry manager. It's a common early mistake to
541leave out the geometry specification, and then be surprised when the
542widget is created but nothing appears. A widget will appear only
543after it has had, for example, the packer's \method{pack()} method
544applied to it.
545
546The pack() method can be called with keyword-option/value pairs that
547control where the widget is to appear within its container, and how it
548is to behave when the main application window is resized. Here are
549some examples:
550
551\begin{verbatim}
552 fred.pack() # defaults to side = "top"
553 fred.pack(side = "left")
554 fred.pack(expand = 1)
555\end{verbatim}
556
557
558\subsubsection{Packer Options}
559
560For more extensive information on the packer and the options that it
561can take, see the man pages and page 183 of John Ousterhout's book.
562
563\begin{description}
564\item[\b{anchor }]
565Anchor type. Denotes where the packer is to place each slave in its
566parcel.
567
568\item[\b{expand}]
569Boolean, \code{0} or \code{1}.
570
571\item[\b{fill}]
572Legal values: \code{'x'}, \code{'y'}, \code{'both'}, \code{'none'}.
573
574\item[\b{ipadx} and \b{ipady}]
575A distance - designating internal padding on each side of the slave
576widget.
577
578\item[\b{padx} and \b{pady}]
579A distance - designating external padding on each side of the slave
580widget.
581
582\item[\b{side}]
583Legal values are: \code{'left'}, \code{'right'}, \code{'top'},
584\code{'bottom'}.
585\end{description}
586
587
588\subsubsection{Coupling Widget Variables} % VarCouplings.html
589
590The current-value setting of some widgets (like text entry widgets)
591can be connected directly to application variables by using special
592options. These options are \code{variable}, \code{textvariable},
593\code{onvalue}, \code{offvalue}, and \code{value}. This
594connection works both ways: if the variable changes for any reason,
595the widget it's connected to will be updated to reflect the new value.
596
597Unfortunately, in the current implementation of \refmodule{Tkinter} it is
598not possible to hand over an arbitrary Python variable to a widget
599through a \code{variable} or \code{textvariable} option. The only
600kinds of variables for which this works are variables that are
601subclassed from a class called Variable, defined in the
602\refmodule{Tkinter} module.
603
604There are many useful subclasses of Variable already defined:
605\class{StringVar}, \class{IntVar}, \class{DoubleVar}, and
606\class{BooleanVar}. To read the current value of such a variable,
607call the \method{get()} method on
608it, and to change its value you call the \method{set()} method. If
609you follow this protocol, the widget will always track the value of
610the variable, with no further intervention on your part.
611
612For example:
613\begin{verbatim}
614class App(Frame):
615 def __init__(self, master=None):
616 Frame.__init__(self, master)
617 self.pack()
618
619 self.entrythingy = Entry()
620 self.entrythingy.pack()
621
622 self.button.pack()
623 # here is the application variable
624 self.contents = StringVar()
625 # set it to some value
626 self.contents.set("this is a variable")
627 # tell the entry widget to watch this variable
628 self.entrythingy["textvariable"] = self.contents
629
630 # and here we get a callback when the user hits return.
631 # we will have the program print out the value of the
632 # application variable when the user hits return
633 self.entrythingy.bind('<Key-Return>',
634 self.print_contents)
635
636 def print_contents(self, event):
637 print "hi. contents of entry is now ---->", \
638 self.contents.get()
639\end{verbatim}
640
641
642\subsubsection{The Window Manager} % WindowMgr.html
643\index{window manager (widgets)}
644
645In Tk, there is a utility command, \code{wm}, for interacting with the
646window manager. Options to the \code{wm} command allow you to control
647things like titles, placement, icon bitmaps, and the like. In
648\refmodule{Tkinter}, these commands have been implemented as methods
649on the \class{Wm} class. Toplevel widgets are subclassed from the
650\class{Wm} class, and so can call the \class{Wm} methods directly.
651
652%See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
653
654To get at the toplevel window that contains a given widget, you can
655often just refer to the widget's master. Of course if the widget has
656been packed inside of a frame, the master won't represent a toplevel
657window. To get at the toplevel window that contains an arbitrary
658widget, you can call the \method{_root()} method. This
659method begins with an underscore to denote the fact that this function
660is part of the implementation, and not an interface to Tk functionality.
661
662Here are some examples of typical usage:
663
664\begin{verbatim}
665import Tkinter
666class App(Frame):
667 def __init__(self, master=None):
668 Frame.__init__(self, master)
669 self.pack()
670
671
672# create the application
673myapp = App()
674
675#
676# here are method calls to the window manager class
677#
678myapp.master.title("My Do-Nothing Application")
679myapp.master.maxsize(1000, 400)
680
681# start the program
682myapp.mainloop()
683\end{verbatim}
684
685
686\subsubsection{Tk Option Data Types} % OptionTypes.html
687
688\index{Tk Option Data Types}
689
690\begin{description}
691\item[anchor]
692Legal values are points of the compass: \code{"n"},
693\code{"ne"}, \code{"e"}, \code{"se"}, \code{"s"},
694\code{"sw"}, \code{"w"}, \code{"nw"}, and also
695\code{"center"}.
696
697\item[bitmap]
698There are eight built-in, named bitmaps: \code{'error'}, \code{'gray25'},
699\code{'gray50'}, \code{'hourglass'}, \code{'info'}, \code{'questhead'},
700\code{'question'}, \code{'warning'}. To specify an X bitmap
701filename, give the full path to the file, preceded with an \code{@},
702as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
703
704\item[boolean]
Neal Norwitzcf57e502002-11-03 13:13:20 +0000705You can pass integers 0 or 1 or the strings \code{"yes"} or \code{"no"} .
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000706
707\item[callback]
708This is any Python function that takes no arguments. For example:
709\begin{verbatim}
710 def print_it():
711 print "hi there"
712 fred["command"] = print_it
713\end{verbatim}
714
715\item[color]
716Colors can be given as the names of X colors in the rgb.txt file,
717or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
718bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
719\code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
720legal hex digit. See page 160 of Ousterhout's book for details.
721
722\item[cursor]
723The standard X cursor names from \file{cursorfont.h} can be used,
724without the \code{XC_} prefix. For example to get a hand cursor
725(\constant{XC_hand2}), use the string \code{"hand2"}. You can also
726specify a bitmap and mask file of your own. See page 179 of
727Ousterhout's book.
728
729\item[distance]
730Screen distances can be specified in either pixels or absolute
731distances. Pixels are given as numbers and absolute distances as
732strings, with the trailing character denoting units: \code{c}
733for centimeters, \code{i} for inches, \code{m} for millimeters,
734\code{p} for printer's points. For example, 3.5 inches is expressed
735as \code{"3.5i"}.
736
737\item[font]
738Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
739Font sizes with positive numbers are measured in points;
740sizes with negative numbers are measured in pixels.
741
742\item[geometry]
743This is a string of the form \samp{\var{width}x\var{height}}, where
744width and height are measured in pixels for most widgets (in
745characters for widgets displaying text). For example:
746\code{fred["geometry"] = "200x100"}.
747
748\item[justify]
749Legal values are the strings: \code{"left"},
750\code{"center"}, \code{"right"}, and \code{"fill"}.
751
752\item[region]
753This is a string with four space-delimited elements, each of
754which is a legal distance (see above). For example: \code{"2 3 4
7555"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
756are all legal regions.
757
758\item[relief]
759Determines what the border style of a widget will be. Legal
760values are: \code{"raised"}, \code{"sunken"},
761\code{"flat"}, \code{"groove"}, and \code{"ridge"}.
762
763\item[scrollcommand]
764This is almost always the \method{set()} method of some scrollbar
765widget, but can be any widget method that takes a single argument.
766Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
767in the Python source distribution for an example.
768
769\item[wrap:]
770Must be one of: \code{"none"}, \code{"char"}, or \code{"word"}.
771\end{description}
772
773
774\subsubsection{Bindings and Events} % Bindings.html
775
776\index{bind (widgets)}
777\index{events (widgets)}
778
779The bind method from the widget command allows you to watch for
780certain events and to have a callback function trigger when that event
781type occurs. The form of the bind method is:
782
783\begin{verbatim}
784 def bind(self, sequence, func, add=''):
785\end{verbatim}
786where:
787
788\begin{description}
789\item[sequence]
790is a string that denotes the target kind of event. (See the bind
791man page and page 201 of John Ousterhout's book for details).
792
793\item[func]
794is a Python function, taking one argument, to be invoked when the
795event occurs. An Event instance will be passed as the argument.
796(Functions deployed this way are commonly known as \var{callbacks}.)
797
798\item[add]
799is optional, either \samp{} or \samp{+}. Passing an empty string
800denotes that this binding is to replace any other bindings that this
801event is associated with. Preceeding with a \samp{+} means that this
802function is to be added to the list of functions bound to this event type.
803\end{description}
804
805For example:
806\begin{verbatim}
807 def turnRed(self, event):
808 event.widget["activeforeground"] = "red"
809
810 self.button.bind("<Enter>", self.turnRed)
811\end{verbatim}
812
813Notice how the widget field of the event is being accesed in the
814\method{turnRed()} callback. This field contains the widget that
815caught the X event. The following table lists the other event fields
816you can access, and how they are denoted in Tk, which can be useful
817when referring to the Tk man pages.
818
819\begin{verbatim}
820Tk Tkinter Event Field Tk Tkinter Event Field
821-- ------------------- -- -------------------
822%f focus %A char
823%h height %E send_event
824%k keycode %K keysym
825%s state %N keysym_num
826%t time %T type
827%w width %W widget
828%x x %X x_root
829%y y %Y y_root
830\end{verbatim}
831
832
833\subsubsection{The index Parameter} % Index.html
834
835A number of widgets require``index'' parameters to be passed. These
836are used to point at a specific place in a Text widget, or to
837particular characters in an Entry widget, or to particular menu items
838in a Menu widget.
839
840\begin{description}
841\item[\b{Entry widget indexes (index, view index, etc.)}]
842Entry widgets have options that refer to character positions in the
843text being displayed. You can use these \refmodule{Tkinter} functions
844to access these special points in text widgets:
Fred Drake666ca802001-11-16 06:02:55 +0000845
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000846\begin{description}
847\item[AtEnd()]
848refers to the last position in the text
Fred Drake666ca802001-11-16 06:02:55 +0000849
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000850\item[AtInsert()]
851refers to the point where the text cursor is
Fred Drake666ca802001-11-16 06:02:55 +0000852
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000853\item[AtSelFirst()]
854indicates the beginning point of the selected text
Fred Drake666ca802001-11-16 06:02:55 +0000855
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000856\item[AtSelLast()]
857denotes the last point of the selected text and finally
Fred Drake666ca802001-11-16 06:02:55 +0000858
859\item[At(x\optional{, y})]
860refers to the character at pixel location \var{x}, \var{y} (with
861\var{y} not used in the case of a text entry widget, which contains a
862single line of text).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000863\end{description}
864
865\item[\b{Text widget indexes}]
866The index notation for Text widgets is very rich and is best described
867in the Tk man pages.
868
869\item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
870
871Some options and methods for menus manipulate specific menu entries.
872Anytime a menu index is needed for an option or a parameter, you may
873pass in:
874\begin{itemize}
875\item an integer which refers to the numeric position of the entry in
876the widget, counted from the top, starting with 0;
877\item the string \code{'active'}, which refers to the menu position that is
878currently under the cursor;
879\item the string \code{"last"} which refers to the last menu
880item;
881\item An integer preceded by \code{@}, as in \code{@6}, where the integer is
882interpreted as a y pixel coordinate in the menu's coordinate system;
883\item the string \code{"none"}, which indicates no menu entry at all, most
884often used with menu.activate() to deactivate all entries, and
885finally,
886\item a text string that is pattern matched against the label of the
887menu entry, as scanned from the top of the menu to the bottom. Note
888that this index type is considered after all the others, which means
889that matches for menu items labelled \code{last}, \code{active}, or
890\code{none} may be interpreted as the above literals, instead.
891\end{itemize}
892\end{description}
893
Martin v. Löwisa288a232002-11-05 22:11:50 +0000894\subsubsection{Images}
895
896Bitmap/Pixelmap images can be created through the subclasses of
897\class{Tkinter.Image}:
898
899\begin{itemize}
900\item \class{BitmapImage} can be used for X11 bitmap data.
901\item \class{PhotoImage} can be used for GIF and PPM/PGM color bitmaps.
902\end{itemize}
903
904Either type of image is created through either the \code{file} or the
905\code{data} option (other options are available as well).
906
Neal Norwitzfad265e2002-11-05 22:46:39 +0000907The image object can then be used wherever an \code{image} option is
Martin v. Löwisa288a232002-11-05 22:11:50 +0000908supported by some widget (e.g. labels, buttons, menus). In these
909cases, Tk will not keep a reference to the image. When the last Python
910reference to the image object is deleted, the image data is deleted as
Neal Norwitzfad265e2002-11-05 22:46:39 +0000911well, and Tk will display an empty box wherever the image was used.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000912
Fred Drakec66ff202001-11-16 01:05:27 +0000913\section{\module{Tix} ---
914 Extension widgets for Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000915
916\declaremodule{standard}{Tix}
917\modulesynopsis{Tk Extension Widgets for Tkinter}
918\sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
919
Fred Drakec66ff202001-11-16 01:05:27 +0000920\index{Tix}
921
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000922The \module{Tix} (Tk Interface Extension) module provides an
923additional rich set of widgets. Although the standard Tk library has
924many useful widgets, they are far from complete. The \module{Tix}
925library provides most of the commonly needed widgets that are missing
926from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
927(a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
928also includes many more widgets that are generally useful in a wide
929range of applications: \class{NoteBook}, \class{FileEntry},
930\class{PanedWindow}, etc; there are more than 40 of them.
931
932With all these new widgets, you can introduce new interaction
933techniques into applications, creating more useful and more intuitive
934user interfaces. You can design your application by choosing the most
935appropriate widgets to match the special needs of your application and
936users.
937
938\begin{seealso}
939\seetitle[http://tix.sourceforge.net/]
940 {Tix Homepage}
Fred Drakea0b76762001-12-13 04:25:37 +0000941 {The home page for \module{Tix}. This includes links to
942 additional documentation and downloads.}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000943\seetitle[http://tix.sourceforge.net/dist/current/man/]
944 {Tix Man Pages}
945 {On-line version of the man pages and reference material.}
946\seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html]
947 {Tix Programming Guide}
948 {On-line version of the programmer's reference material.}
949\seetitle[http://tix.sourceforge.net/Tide/]
950 {Tix Development Applications}
951 {Tix applications for development of Tix and Tkinter programs.
952 Tide applications work under Tk or Tkinter, and include
953 \program{TixInspect}, an inspector to remotely modify and
954 debug Tix/Tk/Tkinter applications.}
955\end{seealso}
956
957
958\subsection{Using Tix}
959
Fred Drake666ca802001-11-16 06:02:55 +0000960\begin{classdesc}{Tix}{screenName\optional{, baseName\optional{, className}}}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000961 Toplevel widget of Tix which represents mostly the main window
962 of an application. It has an associated Tcl interpreter.
963
Fred Drake666ca802001-11-16 06:02:55 +0000964Classes in the \refmodule{Tix} module subclasses the classes in the
965\refmodule{Tkinter} module. The former imports the latter, so to use
966\refmodule{Tix} with Tkinter, all you need to do is to import one
967module. In general, you can just import \refmodule{Tix}, and replace
968the toplevel call to \class{Tkinter.Tk} with \class{Tix.Tk}:
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000969\begin{verbatim}
970import Tix
971from Tkconstants import *
972root = Tix.Tk()
973\end{verbatim}
974\end{classdesc}
975
976To use \refmodule{Tix}, you must have the \refmodule{Tix} widgets installed,
977usually alongside your installation of the Tk widgets.
978To test your installation, try the following:
979\begin{verbatim}
980import Tix
981root = Tix.Tk()
982root.tk.eval('package require Tix')
983\end{verbatim}
984
985If this fails, you have a Tk installation problem which must be
986resolved before proceeding. Use the environment variable \envvar{TIX_LIBRARY}
987to point to the installed \refmodule{Tix} library directory, and
988make sure you have the dynamic object library (\file{tix8183.dll} or
989\file{libtix8183.so}) in the same directory that contains your Tk
990dynamic object library (\file{tk8183.dll} or \file{libtk8183.so}). The
991directory with the dynamic object library should also have a file
992called \file{pkgIndex.tcl} (case sensitive), which contains the line:
993
994\begin{verbatim}
995package ifneeded Tix 8.1 [list load "[file join $dir tix8183.dll]" Tix]
996\end{verbatim} % $ <-- bow to font-lock
997
998
999\subsection{Tix Widgets}
1000
1001\ulink{Tix}
1002{http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm}
1003introduces over 40 widget classes to the \refmodule{Tkinter}
1004repertoire. There is a demo of all the \refmodule{Tix} widgets in the
1005\file{Demo/tix} directory of the standard distribution.
1006
1007
1008% The Python sample code is still being added to Python, hence commented out
1009
1010
1011\subsubsection{Basic Widgets}
1012
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001013\begin{classdesc}{Balloon}{}
1014A \ulink{Balloon}
Fred Drakec66ff202001-11-16 01:05:27 +00001015{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm}
1016that pops up over a widget to provide help. When the user moves the
1017cursor inside a widget to which a Balloon widget has been bound, a
1018small pop-up window with a descriptive message will be shown on the
1019screen.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001020\end{classdesc}
1021
Fred Drakec66ff202001-11-16 01:05:27 +00001022% Python Demo of:
1023% \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001024
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001025\begin{classdesc}{ButtonBox}{}
1026The \ulink{ButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001027{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm}
1028widget creates a box of buttons, such as is commonly used for \code{Ok
1029Cancel}.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001030\end{classdesc}
1031
Fred Drakec66ff202001-11-16 01:05:27 +00001032% Python Demo of:
1033% \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001034
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001035\begin{classdesc}{ComboBox}{}
1036The \ulink{ComboBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001037{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm}
1038widget is similar to the combo box control in MS Windows. The user can
1039select a choice by either typing in the entry subwdget or selecting
1040from the listbox subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001041\end{classdesc}
1042
Fred Drakec66ff202001-11-16 01:05:27 +00001043% Python Demo of:
1044% \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001045
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001046\begin{classdesc}{Control}{}
1047The \ulink{Control}
Fred Drakec66ff202001-11-16 01:05:27 +00001048{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm}
1049widget is also known as the \class{SpinBox} widget. The user can
1050adjust the value by pressing the two arrow buttons or by entering the
1051value directly into the entry. The new value will be checked against
1052the user-defined upper and lower limits.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001053\end{classdesc}
1054
Fred Drakec66ff202001-11-16 01:05:27 +00001055% Python Demo of:
1056% \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001057
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001058\begin{classdesc}{LabelEntry}{}
1059The \ulink{LabelEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001060{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm}
1061widget packages an entry widget and a label into one mega widget. It
1062can be used be used to simplify the creation of ``entry-form'' type of
1063interface.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001064\end{classdesc}
1065
1066% Python Demo of:
1067% \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
1068
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001069\begin{classdesc}{LabelFrame}{}
1070The \ulink{LabelFrame}
Fred Drakec66ff202001-11-16 01:05:27 +00001071{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm}
1072widget packages a frame widget and a label into one mega widget. To
1073create widgets inside a LabelFrame widget, one creates the new widgets
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001074relative to the \member{frame} subwidget and manage them inside the
1075\member{frame} subwidget.
1076\end{classdesc}
1077
1078% Python Demo of:
1079% \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
1080
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001081\begin{classdesc}{Meter}{}
1082The \ulink{Meter}
Fred Drakec66ff202001-11-16 01:05:27 +00001083{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm}
1084widget can be used to show the progress of a background job which may
1085take a long time to execute.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001086\end{classdesc}
1087
1088% Python Demo of:
1089% \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
1090
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001091\begin{classdesc}{OptionMenu}{}
1092The \ulink{OptionMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001093{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm}
1094creates a menu button of options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001095\end{classdesc}
1096
Fred Drakec66ff202001-11-16 01:05:27 +00001097% Python Demo of:
1098% \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001099
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001100\begin{classdesc}{PopupMenu}{}
1101The \ulink{PopupMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001102{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm}
1103widget can be used as a replacement of the \code{tk_popup}
1104command. The advantage of the \refmodule{Tix} \class{PopupMenu} widget
1105is it requires less application code to manipulate.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001106\end{classdesc}
1107
Fred Drakec66ff202001-11-16 01:05:27 +00001108% Python Demo of:
1109% \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001110
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001111\begin{classdesc}{Select}{}
1112The \ulink{Select}
Fred Drakec66ff202001-11-16 01:05:27 +00001113{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm}
1114widget is a container of button subwidgets. It can be used to provide
1115radio-box or check-box style of selection options for the user.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001116\end{classdesc}
1117
Fred Drakec66ff202001-11-16 01:05:27 +00001118% Python Demo of:
1119% \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001120
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001121\begin{classdesc}{StdButtonBox}{}
1122The \ulink{StdButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001123{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm}
1124widget is a group of standard buttons for Motif-like dialog boxes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001125\end{classdesc}
1126
Fred Drakec66ff202001-11-16 01:05:27 +00001127% Python Demo of:
1128% \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001129
1130
1131\subsubsection{File Selectors}
1132
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001133\begin{classdesc}{DirList}{}
1134The \ulink{DirList}
1135{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm} widget
1136displays a list view of a directory, its previous directories and its
1137sub-directories. The user can choose one of the directories displayed
1138in the list or change to another directory.
1139\end{classdesc}
1140
Fred Drakec66ff202001-11-16 01:05:27 +00001141% Python Demo of:
1142% \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001143
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001144\begin{classdesc}{DirTree}{}
1145The \ulink{DirTree}
Fred Drakec66ff202001-11-16 01:05:27 +00001146{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm}
1147widget displays a tree view of a directory, its previous directories
1148and its sub-directories. The user can choose one of the directories
1149displayed in the list or change to another directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001150\end{classdesc}
1151
Fred Drakec66ff202001-11-16 01:05:27 +00001152% Python Demo of:
1153% \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001154
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001155\begin{classdesc}{DirSelectDialog}{}
1156The \ulink{DirSelectDialog}
Fred Drakec66ff202001-11-16 01:05:27 +00001157{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm}
1158widget presents the directories in the file system in a dialog
1159window. The user can use this dialog window to navigate through the
1160file system to select the desired directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001161\end{classdesc}
1162
Fred Drakec66ff202001-11-16 01:05:27 +00001163% Python Demo of:
1164% \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001165
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001166\begin{classdesc}{DirSelectBox}{}
1167The \class{DirSelectBox} is similar
1168to the standard Motif(TM) directory-selection box. It is generally used for
1169the user to choose a directory. DirSelectBox stores the directories mostly
1170recently selected into a ComboBox widget so that they can be quickly
1171selected again.
1172\end{classdesc}
1173
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001174\begin{classdesc}{ExFileSelectBox}{}
1175The \ulink{ExFileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001176{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm}
1177widget is usually embedded in a tixExFileSelectDialog widget. It
1178provides an convenient method for the user to select files. The style
1179of the \class{ExFileSelectBox} widget is very similar to the standard
1180file dialog on MS Windows 3.1.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001181\end{classdesc}
1182
Fred Drakec66ff202001-11-16 01:05:27 +00001183% Python Demo of:
1184%\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001185
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001186\begin{classdesc}{FileSelectBox}{}
1187The \ulink{FileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001188{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm}
1189is similar to the standard Motif(TM) file-selection box. It is
1190generally used for the user to choose a file. FileSelectBox stores the
1191files mostly recently selected into a \class{ComboBox} widget so that
1192they can be quickly selected again.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001193\end{classdesc}
1194
Fred Drakec66ff202001-11-16 01:05:27 +00001195% Python Demo of:
1196% \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001197
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001198\begin{classdesc}{FileEntry}{}
1199The \ulink{FileEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001200{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm}
1201widget can be used to input a filename. The user can type in the
1202filename manually. Alternatively, the user can press the button widget
1203that sits next to the entry, which will bring up a file selection
1204dialog.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001205\end{classdesc}
1206
Fred Drakec66ff202001-11-16 01:05:27 +00001207% Python Demo of:
1208% \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001209
1210
1211\subsubsection{Hierachical ListBox}
1212
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001213\begin{classdesc}{HList}{}
1214The \ulink{HList}
Fred Drakec66ff202001-11-16 01:05:27 +00001215{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm}
1216widget can be used to display any data that have a hierarchical
1217structure, for example, file system directory trees. The list entries
1218are indented and connected by branch lines according to their places
1219in the hierachy.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001220\end{classdesc}
1221
Fred Drakec66ff202001-11-16 01:05:27 +00001222% Python Demo of:
1223% \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001224
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001225\begin{classdesc}{CheckList}{}
1226The \ulink{CheckList}
Fred Drakec66ff202001-11-16 01:05:27 +00001227{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm}
1228widget displays a list of items to be selected by the user. CheckList
1229acts similarly to the Tk checkbutton or radiobutton widgets, except it
1230is capable of handling many more items than checkbuttons or
1231radiobuttons.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001232\end{classdesc}
1233
Fred Drakec66ff202001-11-16 01:05:27 +00001234% Python Demo of:
1235% \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
1236% Python Demo of:
1237% \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
1238% Python Demo of:
1239% \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001240
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001241\begin{classdesc}{Tree}{}
1242The \ulink{Tree}
Fred Drakec66ff202001-11-16 01:05:27 +00001243{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm}
1244widget can be used to display hierachical data in a tree form. The
1245user can adjust the view of the tree by opening or closing parts of
1246the tree.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001247\end{classdesc}
1248
Fred Drakec66ff202001-11-16 01:05:27 +00001249% Python Demo of:
1250% \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001251
Fred Drakec66ff202001-11-16 01:05:27 +00001252% Python Demo of:
1253% \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001254
1255
1256\subsubsection{Tabular ListBox}
1257
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001258\begin{classdesc}{TList}{}
1259The \ulink{TList}
Fred Drakec66ff202001-11-16 01:05:27 +00001260{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm}
1261widget can be used to display data in a tabular format. The list
1262entries of a \class{TList} widget are similar to the entries in the Tk
1263listbox widget. The main differences are (1) the \class{TList} widget
1264can display the list entries in a two dimensional format and (2) you
1265can use graphical images as well as multiple colors and fonts for the
1266list entries.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001267\end{classdesc}
1268
Fred Drakec66ff202001-11-16 01:05:27 +00001269% Python Demo of:
1270% \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
1271% Python Demo of:
1272% \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001273
1274% Grid has yet to be added to Python
1275% \subsubsection{Grid Widget}
Fred Drakec66ff202001-11-16 01:05:27 +00001276% Python Demo of:
1277% \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
1278% Python Demo of:
1279% \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
1280% Python Demo of:
1281% \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001282
1283
1284\subsubsection{Manager Widgets}
1285
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001286\begin{classdesc}{PanedWindow}{}
1287The \ulink{PanedWindow}
Fred Drakec66ff202001-11-16 01:05:27 +00001288{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm}
1289widget allows the user to interactively manipulate the sizes of
1290several panes. The panes can be arranged either vertically or
1291horizontally. The user changes the sizes of the panes by dragging the
1292resize handle between two panes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001293\end{classdesc}
1294
Fred Drakec66ff202001-11-16 01:05:27 +00001295% Python Demo of:
1296% \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001297
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001298\begin{classdesc}{ListNoteBook}{}
1299The \ulink{ListNoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001300{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm}
1301widget is very similar to the \class{TixNoteBook} widget: it can be
1302used to display many windows in a limited space using a notebook
1303metaphor. The notebook is divided into a stack of pages (windows). At
1304one time only one of these pages can be shown. The user can navigate
1305through these pages by choosing the name of the desired page in the
1306\member{hlist} subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001307\end{classdesc}
1308
Fred Drakec66ff202001-11-16 01:05:27 +00001309% Python Demo of:
1310% \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001311
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001312\begin{classdesc}{NoteBook}{}
1313The \ulink{NoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001314{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm}
1315widget can be used to display many windows in a limited space using a
1316notebook metaphor. The notebook is divided into a stack of pages. At
1317one time only one of these pages can be shown. The user can navigate
1318through these pages by choosing the visual ``tabs'' at the top of the
1319NoteBook widget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001320\end{classdesc}
1321
Fred Drakec66ff202001-11-16 01:05:27 +00001322% Python Demo of:
1323% \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001324
1325
1326% \subsubsection{Scrolled Widgets}
Fred Drakec66ff202001-11-16 01:05:27 +00001327% Python Demo of:
1328% \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
1329% Python Demo of:
1330% \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
1331% Python Demo of:
1332% \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
1333% Python Demo of:
1334% \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001335
1336
1337\subsubsection{Image Types}
1338
1339The \refmodule{Tix} module adds:
1340\begin{itemize}
1341\item
1342\ulink{pixmap}
Fred Drake666ca802001-11-16 06:02:55 +00001343{http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm}
1344capabilities to all \refmodule{Tix} and \refmodule{Tkinter} widgets to
1345create color images from XPM files.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001346
Fred Drakea0b76762001-12-13 04:25:37 +00001347% Python Demo of:
1348% \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001349
Fred Drakea0b76762001-12-13 04:25:37 +00001350% Python Demo of:
1351% \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001352
1353\item
1354\ulink{Compound}
Fred Drake666ca802001-11-16 06:02:55 +00001355{http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html}
1356image types can be used to create images that consists of multiple
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001357horizontal lines; each line is composed of a series of items (texts,
1358bitmaps, images or spaces) arranged from left to right. For example, a
1359compound image can be used to display a bitmap and a text string
1360simutaneously in a Tk \class{Button} widget.
1361
Fred Drake666ca802001-11-16 06:02:55 +00001362% Python Demo of:
1363% \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001364
Fred Drake666ca802001-11-16 06:02:55 +00001365% Python Demo of:
1366% \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001367
Fred Drake666ca802001-11-16 06:02:55 +00001368% Python Demo of:
1369% \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001370
Fred Drake666ca802001-11-16 06:02:55 +00001371% Python Demo of:
1372% \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001373\end{itemize}
1374
1375
1376\subsubsection{Miscellaneous Widgets}
1377
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001378\begin{classdesc}{InputOnly}{}
1379The \ulink{InputOnly}
Fred Drake666ca802001-11-16 06:02:55 +00001380{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
1381widgets are to accept inputs from the user, which can be done with the
1382\code{bind} command (\UNIX{} only).
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001383\end{classdesc}
1384
1385\subsubsection{Form Geometry Manager}
1386
1387In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
Fred Drake666ca802001-11-16 06:02:55 +00001388
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001389\begin{classdesc}{Form}{}
1390The \ulink{Form}
Fred Drake666ca802001-11-16 06:02:55 +00001391{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
1392geometry manager based on attachment rules for all Tk widgets.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001393\end{classdesc}
1394
1395
1396%begin{latexonly}
1397%\subsection{Tix Class Structure}
1398%
1399%\begin{figure}[hbtp]
1400%\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
1401%\vspace{.5cm}
1402%\caption{The Class Hierarchy of Tix Widgets}
1403%\end{figure}
1404%end{latexonly}
1405
Fred Drake44b6f842001-11-29 21:09:08 +00001406\subsection{Tix Commands}
1407
1408\begin{classdesc}{tixCommand}{}
1409The \ulink{tix commands}
1410{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
1411provide access to miscellaneous elements of \refmodule{Tix}'s internal
1412state and the \refmodule{Tix} application context. Most of the information
1413manipulated by these methods pertains to the application as a whole,
1414or to a screen or display, rather than to a particular window.
1415
1416To view the current settings, the common usage is:
1417\begin{verbatim}
1418import Tix
1419root = Tix.Tk()
1420print root.tix_configure()
1421\end{verbatim}
1422\end{classdesc}
1423
1424\begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
1425Query or modify the configuration options of the Tix application
1426context. If no option is specified, returns a dictionary all of the
1427available options. If option is specified with no value, then the
1428method returns a list describing the one named option (this list will
1429be identical to the corresponding sublist of the value returned if no
1430option is specified). If one or more option-value pairs are
1431specified, then the method modifies the given option(s) to have the
1432given value(s); in this case the method returns an empty string.
1433Option may be any of the configuration options.
1434\end{methoddesc}
1435
1436\begin{methoddesc}{tix_cget}{option}
1437Returns the current value of the configuration option given by
1438\var{option}. Option may be any of the configuration options.
1439\end{methoddesc}
1440
1441\begin{methoddesc}{tix_getbitmap}{name}
1442Locates a bitmap file of the name \code{name.xpm} or \code{name} in
1443one of the bitmap directories (see the \method{tix_addbitmapdir()}
1444method). By using \method{tix_getbitmap()}, you can avoid hard
1445coding the pathnames of the bitmap files in your application. When
1446successful, it returns the complete pathname of the bitmap file,
1447prefixed with the character \samp{@}. The returned value can be used to
1448configure the \code{bitmap} option of the Tk and Tix widgets.
1449\end{methoddesc}
1450
1451\begin{methoddesc}{tix_addbitmapdir}{directory}
1452Tix maintains a list of directories under which the
1453\method{tix_getimage()} and \method{tix_getbitmap()} methods will
1454search for image files. The standard bitmap directory is
1455\file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
1456adds \var{directory} into this list. By using this method, the image
1457files of an applications can also be located using the
1458\method{tix_getimage()} or \method{tix_getbitmap()} method.
1459\end{methoddesc}
1460
1461\begin{methoddesc}{tix_filedialog}{\optional{dlgclass}}
1462Returns the file selection dialog that may be shared among different
1463calls from this application. This method will create a file selection
1464dialog widget when it is called the first time. This dialog will be
1465returned by all subsequent calls to \method{tix_filedialog()}. An
1466optional dlgclass parameter can be passed as a string to specified
1467what type of file selection dialog widget is desired. Possible
1468options are \code{tix}, \code{FileSelectDialog} or
1469\code{tixExFileSelectDialog}.
1470\end{methoddesc}
1471
1472
1473\begin{methoddesc}{tix_getimage}{self, name}
1474Locates an image file of the name \file{name.xpm}, \file{name.xbm} or
1475\file{name.ppm} in one of the bitmap directories (see the
1476\method{tix_addbitmapdir()} method above). If more than one file with
1477the same name (but different extensions) exist, then the image type is
1478chosen according to the depth of the X display: xbm images are chosen
1479on monochrome displays and color images are chosen on color
1480displays. By using \method{tix_getimage()}, you can avoid hard coding
1481the pathnames of the image files in your application. When successful,
1482this method returns the name of the newly created image, which can be
1483used to configure the \code{image} option of the Tk and Tix widgets.
1484\end{methoddesc}
1485
1486\begin{methoddesc}{tix_option_get}{name}
1487Gets the options manitained by the Tix scheme mechanism.
1488\end{methoddesc}
1489
1490\begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
1491 newScmPrio}}
1492Resets the scheme and fontset of the Tix application to
1493\var{newScheme} and \var{newFontSet}, respectively. This affects only
1494those widgets created after this call. Therefore, it is best to call
1495the resetoptions method before the creation of any widgets in a Tix
1496application.
1497
1498The optional parameter \var{newScmPrio} can be given to reset the
1499priority level of the Tk options set by the Tix schemes.
1500
1501Because of the way Tk handles the X option database, after Tix has
1502been has imported and inited, it is not possible to reset the color
1503schemes and font sets using the \method{tix_config()} method.
1504Instead, the \method{tix_resetoptions()} method must be used.
1505\end{methoddesc}
1506
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001507
Fred Drake1a763862001-12-03 21:18:30 +00001508
1509\section{\module{ScrolledText} ---
1510 Scrolled Text Widget}
1511
1512\declaremodule{standard}{ScrolledText}
1513 \platform{Tk}
1514\modulesynopsis{Text widget with a vertical scroll bar.}
1515\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
1516
1517The \module{ScrolledText} module provides a class of the same name
1518which implements a basic text widget which has a vertical scroll bar
1519configured to do the ``right thing.'' Using the \class{ScrolledText}
1520class is a lot easier than setting up a text widget and scroll bar
1521directly. The constructor is the same as that of the
1522\class{Tkinter.Text} class.
1523
1524The text widget and scrollbar are packed together in a \class{Frame},
Fred Drakea0b76762001-12-13 04:25:37 +00001525and the methods of the \class{Grid} and \class{Pack} geometry managers
1526are acquired from the \class{Frame} object. This allows the
1527\class{ScrolledText} widget to be used directly to achieve most normal
1528geometry management behavior.
Fred Drake1a763862001-12-03 21:18:30 +00001529
1530Should more specific control be necessary, the following attributes
1531are available:
1532
1533\begin{memberdesc}[ScrolledText]{frame}
1534 The frame which surrounds the text and scroll bar widgets.
1535\end{memberdesc}
1536
1537\begin{memberdesc}[ScrolledText]{vbar}
1538 The scroll bar widget.
1539\end{memberdesc}
1540
1541
Fred Drakec66ff202001-11-16 01:05:27 +00001542\input{libturtle}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001543
1544
1545\section{Idle \label{idle}}
1546
1547%\declaremodule{standard}{idle}
1548%\modulesynopsis{A Python Integrated Developement Environment}
1549\moduleauthor{Guido van Rossum}{guido@Python.org}
1550
1551Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
1552\index{Idle}
1553\index{Python Editor}
1554\index{Integrated Developement Environment}
1555
1556
1557IDLE has the following features:
1558
1559\begin{itemize}
1560\item coded in 100\% pure Python, using the \refmodule{Tkinter} GUI toolkit
1561
1562\item cross-platform: works on Windows and \UNIX{} (on Mac OS, there are
1563currently problems with Tcl/Tk)
1564
1565\item multi-window text editor with multiple undo, Python colorizing
1566and many other features, e.g. smart indent and call tips
1567
1568\item Python shell window (a.k.a. interactive interpreter)
1569
1570\item debugger (not complete, but you can set breakpoints, view and step)
1571\end{itemize}
1572
1573
1574\subsection{Menus}
1575
1576\subsubsection{File menu}
1577
1578\begin{description}
1579\item[New window] create a new editing window
1580\item[Open...] open an existing file
1581\item[Open module...] open an existing module (searches sys.path)
1582\item[Class browser] show classes and methods in current file
1583\item[Path browser] show sys.path directories, modules, classes and methods
1584\end{description}
1585\index{Class browser}
1586\index{Path browser}
1587
1588\begin{description}
1589\item[Save] save current window to the associated file (unsaved
1590windows have a * before and after the window title)
1591
1592\item[Save As...] save current window to new file, which becomes
1593the associated file
1594\item[Save Copy As...] save current window to different file
1595without changing the associated file
1596\end{description}
1597
1598\begin{description}
1599\item[Close] close current window (asks to save if unsaved)
1600\item[Exit] close all windows and quit IDLE (asks to save if unsaved)
1601\end{description}
1602
1603
1604\subsubsection{Edit menu}
1605
1606\begin{description}
1607\item[Undo] Undo last change to current window (max 1000 changes)
1608\item[Redo] Redo last undone change to current window
1609\end{description}
1610
1611\begin{description}
1612\item[Cut] Copy selection into system-wide clipboard; then delete selection
1613\item[Copy] Copy selection into system-wide clipboard
1614\item[Paste] Insert system-wide clipboard into window
1615\item[Select All] Select the entire contents of the edit buffer
1616\end{description}
1617
1618\begin{description}
1619\item[Find...] Open a search dialog box with many options
1620\item[Find again] Repeat last search
1621\item[Find selection] Search for the string in the selection
1622\item[Find in Files...] Open a search dialog box for searching files
1623\item[Replace...] Open a search-and-replace dialog box
1624\item[Go to line] Ask for a line number and show that line
1625\end{description}
1626
1627\begin{description}
1628\item[Indent region] Shift selected lines right 4 spaces
1629\item[Dedent region] Shift selected lines left 4 spaces
1630\item[Comment out region] Insert \#\# in front of selected lines
1631\item[Uncomment region] Remove leading \# or \#\# from selected lines
1632\item[Tabify region] Turns \emph{leading} stretches of spaces into tabs
1633\item[Untabify region] Turn \emph{all} tabs into the right number of spaces
1634\item[Expand word] Expand the word you have typed to match another
1635 word in the same buffer; repeat to get a different expansion
1636\item[Format Paragraph] Reformat the current blank-line-separated paragraph
1637\end{description}
1638
1639\begin{description}
1640\item[Import module] Import or reload the current module
1641\item[Run script] Execute the current file in the __main__ namespace
1642\end{description}
1643
1644\index{Import module}
1645\index{Run script}
1646
1647
1648\subsubsection{Windows menu}
1649
1650\begin{description}
1651\item[Zoom Height] toggles the window between normal size (24x80)
1652 and maximum height.
1653\end{description}
1654
1655The rest of this menu lists the names of all open windows; select one
1656to bring it to the foreground (deiconifying it if necessary).
1657
1658
1659\subsubsection{Debug menu (in the Python Shell window only)}
1660
1661\begin{description}
1662\item[Go to file/line] look around the insert point for a filename
1663 and linenumber, open the file, and show the line.
1664\item[Open stack viewer] show the stack traceback of the last exception
1665\item[Debugger toggle] Run commands in the shell under the debugger
1666\item[JIT Stack viewer toggle] Open stack viewer on traceback
1667\end{description}
1668
1669\index{stack viewer}
1670\index{debugger}
1671
1672
1673\subsection{Basic editing and navigation}
1674
1675\begin{itemize}
1676\item \kbd{Backspace} deletes to the left; \kbd{Del} deletes to the right
1677\item Arrow keys and \kbd{Page Up}/\kbd{Page Down} to move around
1678\item \kbd{Home}/\kbd{End} go to begin/end of line
1679\item \kbd{C-Home}/\kbd{C-End} go to begin/end of file
1680\item Some \program{Emacs} bindings may also work, including \kbd{C-B},
1681 \kbd{C-P}, \kbd{C-A}, \kbd{C-E}, \kbd{C-D}, \kbd{C-L}
1682\end{itemize}
1683
1684
1685\subsubsection{Automatic indentation}
1686
1687After a block-opening statement, the next line is indented by 4 spaces
1688(in the Python Shell window by one tab). After certain keywords
1689(break, return etc.) the next line is dedented. In leading
1690indentation, \kbd{Backspace} deletes up to 4 spaces if they are there.
1691\kbd{Tab} inserts 1-4 spaces (in the Python Shell window one tab).
1692See also the indent/dedent region commands in the edit menu.
1693
1694
1695\subsubsection{Python Shell window}
1696
1697\begin{itemize}
1698\item \kbd{C-C} interrupts executing command
1699\item \kbd{C-D} sends end-of-file; closes window if typed at
1700a \samp{>>>~} prompt
1701\end{itemize}
1702
1703\begin{itemize}
Fred Drake666ca802001-11-16 06:02:55 +00001704\item \kbd{Alt-p} retrieves previous command matching what you have typed
1705\item \kbd{Alt-n} retrieves next
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001706\item \kbd{Return} while on any previous command retrieves that command
Fred Drake666ca802001-11-16 06:02:55 +00001707\item \kbd{Alt-/} (Expand word) is also useful here
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001708\end{itemize}
1709
1710\index{indentation}
1711
1712
1713\subsection{Syntax colors}
1714
1715The coloring is applied in a background ``thread,'' so you may
1716occasionally see uncolorized text. To change the color
1717scheme, edit the \code{[Colors]} section in \file{config.txt}.
1718
1719\begin{description}
1720\item[Python syntax colors:]
1721
1722\begin{description}
1723\item[Keywords] orange
1724\item[Strings ] green
1725\item[Comments] red
1726\item[Definitions] blue
1727\end{description}
1728
1729\item[Shell colors:]
1730\begin{description}
1731\item[Console output] brown
1732\item[stdout] blue
1733\item[stderr] dark green
1734\item[stdin] black
1735\end{description}
1736\end{description}
1737
1738
1739\subsubsection{Command line usage}
1740
1741\begin{verbatim}
1742idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
1743
1744-c command run this command
1745-d enable debugger
1746-e edit mode; arguments are files to be edited
1747-s run $IDLESTARTUP or $PYTHONSTARTUP first
1748-t title set title of shell window
1749\end{verbatim}
1750
1751If there are arguments:
1752
1753\begin{enumerate}
1754\item If \programopt{-e} is used, arguments are files opened for
1755 editing and \code{sys.argv} reflects the arguments passed to
1756 IDLE itself.
1757
1758\item Otherwise, if \programopt{-c} is used, all arguments are
1759 placed in \code{sys.argv[1:...]}, with \code{sys.argv[0]} set
1760 to \code{'-c'}.
1761
1762\item Otherwise, if neither \programopt{-e} nor \programopt{-c} is
1763 used, the first argument is a script which is executed with
1764 the remaining arguments in \code{sys.argv[1:...]} and
1765 \code{sys.argv[0]} set to the script name. If the script name
1766 is '-', no script is executed but an interactive Python
1767 session is started; the arguments are still available in
1768 \code{sys.argv}.
1769\end{enumerate}
Fred Drakec66ff202001-11-16 01:05:27 +00001770
1771
1772\section{Other Graphical User Interface Packages
1773 \label{other-gui-packages}}
1774
1775
1776There are an number of extension widget sets to \refmodule{Tkinter}.
1777
Fred Drake10cd3152001-11-30 18:17:24 +00001778\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001779\seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
1780toolkit for building high-level compound widgets in Python using the
1781\refmodule{Tkinter} module. It consists of a set of base classes and
1782a library of flexible and extensible megawidgets built on this
1783foundation. These megawidgets include notebooks, comboboxes, selection
1784widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1785with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1786and vector commands are be available.
1787
1788The initial ideas for Pmw were taken from the Tk \code{itcl}
1789extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
1790Widgets]} by Mark Ulferts. Several of the megawidgets are direct
1791translations from the itcl to Python. It offers most of the range of
1792widgets that \code{[incr Widgets]} does, and is almost as complete as
1793Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
1794}
Fred Drake81209952003-07-08 13:44:27 +00001795
1796\seetitle[http://tkinter.effbot.org/]{Tkinter3000 Widget Construction
1797 Kit (WCK)}{%
1798is a library that allows you to write new Tkinter widgets in pure
1799Python. The WCK framework gives you full control over widget
1800creation, configuration, screen appearance, and event handling. WCK
1801widgets can be very fast and light-weight, since they can operate
1802directly on Python data structures, without having to transfer data
1803through the Tk/Tcl layer.}
Fred Drake10cd3152001-11-30 18:17:24 +00001804\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001805
1806
Fred Drake666ca802001-11-16 06:02:55 +00001807Tk is not the only GUI for Python, but is however the
Fred Drakec66ff202001-11-16 01:05:27 +00001808most commonly used one.
1809
Fred Drake10cd3152001-11-30 18:17:24 +00001810\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001811\seetitle[http://www.wxwindows.org]{wxWindows}{
1812is a GUI toolkit that combines the most attractive attributes of Qt,
1813Tk, Motif, and GTK+ in one powerful and efficient package. It is
Fred Drakec37b65e2001-11-28 07:26:15 +00001814implemented in \Cpp. wxWindows supports two flavors of \UNIX{}
Fred Drakec66ff202001-11-16 01:05:27 +00001815implementation: GTK+ and Motif, and under Windows, it has a standard
1816Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1817widgets. There is a Python class wrapper, independent of Tkinter.
1818
1819wxWindows is much richer in widgets than \refmodule{Tkinter}, with its
1820help system, sophisticated HTML and image viewers, and other
1821specialized widgets, extensive documentation, and printing capabilities.
1822}
Fred Drake9b414ac2002-05-31 18:21:56 +00001823\seetitle[]{PyQt}{
1824PyQt is a \program{sip}-wrapped binding to the Qt toolkit. Qt is an
1825extensive \Cpp{} GUI toolkit that is available for \UNIX, Windows and
1826Mac OS X. \program{sip} is a tool for generating bindings for \Cpp{}
1827libraries as Python classes, and is specifically designed for Python.
1828An online manual is available at
1829\url{http://www.opendocspublishing.com/pyqt/} (errata are located at
1830\url{http://www.valdyas.org/python/book.html}).
1831}
1832\seetitle[http://www.riverbankcomputing.co.uk/pykde/index.php]{PyKDE}{
1833PyKDE is a \program{sip}-wrapped interface to the KDE desktop
1834libraries. KDE is a desktop environment for \UNIX{} computers; the
1835graphical components are based on Qt.
Fred Drakec66ff202001-11-16 01:05:27 +00001836}
1837\seetitle[http://fxpy.sourceforge.net/]{FXPy}{
1838is a Python extension module which provides an interface to the
1839\citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
1840FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
1841easily and effectively. It offers a wide, and growing, collection of
1842Controls, and provides state of the art facilities such as drag and
1843drop, selection, as well as OpenGL widgets for 3D graphical
1844manipulation. FOX also implements icons, images, and user-convenience
1845features such as status line help, and tooltips.
1846
1847Even though FOX offers a large collection of controls already, FOX
1848leverages \Cpp{} to allow programmers to easily build additional Controls
1849and GUI elements, simply by taking existing controls, and creating a
1850derived class which simply adds or redefines the desired behavior.
1851}
Fred Draked50bd6c2003-07-28 14:39:13 +00001852\seetitle[http://www.daa.com.au/\textasciitilde james/software/pygtk/]{PyGTK}{
Fred Drakec66ff202001-11-16 01:05:27 +00001853is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
1854It provides an object oriented interface that is slightly higher
1855level than the C one. It automatically does all the type casting and
1856reference counting that you would have to do normally with the C
Fred Drake16ecb212002-10-12 15:02:46 +00001857API. There are also
1858\ulink{bindings}{http://www.daa.com.au/\textasciitilde james/gnome/}
Fred Drakec66ff202001-11-16 01:05:27 +00001859to \ulink{GNOME}{http://www.gnome.org}, and a
1860\ulink{tutorial}
Fred Drake16ecb212002-10-12 15:02:46 +00001861{http://laguna.fmedic.unam.mx/\textasciitilde daniel/pygtutorial/pygtutorial/index.html}
Fred Drakec66ff202001-11-16 01:05:27 +00001862is available.
1863}
Fred Drake10cd3152001-11-30 18:17:24 +00001864\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001865
1866% XXX Reference URLs that compare the different UI packages