17.3. Bitmap PrimitivesPrior to the advent of images, Tk supported simple bitmap operations. All the button-like widgets, plus Canvas, Dialog, and Label, have a -bitmap option whose value is either a string specifying a built-in bitmap name or an XBM filename with a leading @ character. This code displays the built-in bitmaps and an XBM file:
Figure 17-2 shows the bitmaps. ![]() Figure 17-2. Bitmaps are built-in or read from a fileBitmaps are also used as application icons and cursors. MainWindows and Toplevels have iconbitmap and iconmask methods that define an application icon:
Tk provides scores of built-in cursors, depicted in Figure 23-2. To build your own cursor, you need an XBM file and a mask file. A cursor specification is a reference to an array of four elements: [qw\@images/mouse.xbm images/mouse.mask blue yellow\] The array elements are the XBM filename, the mask filename, the foreground color, and the background color. The file mouse.xbm looks like this:
Notice that a cursor bitmap requires two extra statements, which comprise an x and y "hot spot" that specifies what part of the bitmap is the actual "pointer." Here is the content of file mouse.mask, the corresponding mask:
Configuring a widget's -cursor option with these bitmap and mask files produces the mouse cursor shown in Figure 17-3, which the neko might find very interesting. Figure 17-3. Neko mouse cursorNote that the -bitmap and -cursor options can take only a built-in name or XBM filename (with the leading @). You'll have to use DefineBitmap or a Bitmap image to specify your bitmap as inline data. For more details on cursors, see Chapter 23, "Plethora of pTk Potpourri".
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|