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