11.7. How do I change the cursor/color?

Nick Ing-Simmons <nik@tiuk.ti.com> and others posted a series of answers to this type of question. In summary what they said was:

Basically
    $mw->configure(-cursor => ... );
Unless you use one of built-in cursors it gets messy.

Here copy of what Tk/demos/color_editor does:

    #!/usr/local/bin/perl -w
    use Tk;
    my $mw = MainWindow->new;
    $mw->configure(-cursor => ['@' . Tk->findINC('demos/images/cursor.xbm'), 
                                    Tk->findINC('demos/images/cursor.mask'),
                                     'red', 'green']);
    MainLoop;
That says that argument to -cursor is a list of 4 things:
  1. . Pathname to bitmap with '@' prepended to say it isn't a built in name (Using findINC to locate file relative to Tk install location.)
  2. . Pathname to mask bitmap (no @ required)
  3. . Foreground colour
  4. . Background colour

! I want to remap it for the MainWindow
! and will be using a pixmap.
You won't be using a Pixmap with normal X11. X11 allows *bitmap* with optional mask (another bitmap), and two colours.

The optional nature of the mask means that a simple call with a list reference like:

    $mw->configure(-cursor => ['watch', 'red', 'blue']);
should work alright.

You may also obtain the value of the default cursor for a widget using something like ->optionGet.


Previous | Return to table of contents | Next