I need to pass the identity of the current tab displayed worksheetThere are a couple of ways, one is to use the raisecmd callback, to set the current page.
This will make a callback for the current page, with a right-click release.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::NoteBook;
my $current = 0;
my $mw=MainWindow->new(-title=>'Notebook tab colors demo');
my $XIMG = <<'EOF';
/* XPM */
static char * x_xpm[] = {
"12 12 3 1",
" c None",
". c #FF6060",
"+ c #8F6060",
" . . ",
" .+. .+. ",
".+++. .+++. ",
"+.+++.+++.+ ",
" +.+++++.+ ",
" +.+++.+ ",
" .+++++. ",
" .+++.+++. ",
".+++.+.+++. ",
"+.+.+ +.+.+ ",
" +.+ +.+ ",
" + + "};
EOF
my $RED = $mw->Pixmap(-data => $XIMG );
my $BXIMG = $XIMG;
$BXIMG =~ s/#FF6060/#6060FF/;
$BXIMG =~ s/#8F6060/#60608F/;
my $BLUE = $mw->Pixmap(-data => $BXIMG );
my $GXIMG = $XIMG;
$GXIMG =~ s/#FF6060/#60FF60/;
$GXIMG =~ s/#8F6060/#60FF60/;
my $GREEN = $mw->Pixmap(-data => $GXIMG );
my $nb = $mw->NoteBook(
-background=> 'white',
-inactivebackground => 'black',
)->pack();
$nb->bind('<ButtonRelease-3>', sub{
print "$current is being saved\n";
});
my @colors = ($RED,$BLUE,$GREEN);
for my $tab (qw/page1 page2 page3 page4 page5 page6/){
my $frame = $nb->add($tab,
-raisecmd => sub{ print "@_\n";
print $tab,"\n";
$current = $tab;
print "$current is current\n";
},
-image=> $colors[0], );
$frame->Label(-text => $tab)->pack;
$frame->Label(-text => 'a Label in '.$tab)->pack;
push (@colors,shift(@colors)); #shift colors around
}
MainLoop;
|