O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Manipulating the Cursor

Every Tk widget has a cursor shape associated with it. Most default to what’s known as the left_ptr shape, shown in Figure 23-1.

The standard cursor for most widgets

Figure 23-1. The standard cursor for most widgets

The cursor shape can be changed on a widget-by-widget basis with the -cursor option:

$mw->Button(-text => 'Go ...', -cursor => cursor_name);

When the mouse is over the Button, the cursor changes to the one specified. The cursor change happens whether the Button is disabled or not. The set of available cursors is quite large. Figure 23-2 shows the cursor shapes available on most systems.

Cursor shapes available on most systems

Figure 23-2.  Cursor shapes available on most systems

Here’s a program to look at the different cursors interactively. It’s really simple, just a Listbox full of cursor shape names and a button binding that changes the application’s cursor. The hardest part is figuring out where the list of cursor names is hidden.

$mw = MainWindow->new; $mw->Button(-text => "Exit", -command => sub { exit })->pack(-side => "bottom", -fill => "x"); $scroll = $mw->Scrollbar; $lb = $mw->Listbox(-selectmode => 'single', -yscrollcommand => [set => $scroll]); $scroll->configure(-command => [yview => $lb]); $scroll->pack(-side => 'right', -fill => 'y'); $lb->pack(-side => 'left', -fill => 'both'); ## Open file that contains all ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required