Errata

Mastering Perl/Tk

Errata for Mastering Perl/Tk

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page 76

The program for Using Fonts Dynamically doesn't work with fonts which name contains spaces.
The program requires 2 modifications to work:
1) Change de font name from "$name$_" to "{$name}$_" as indicated in page 75.
2) Chane the name of tag name in configuring tags dynamically so it don't contains spaces.

memo.garciasir  Dec 29, 2008 
Other Digital Version 222
source code

I copied the source code for the drawing program example on page 222 and tried to run it but it doesn't let me draw anything.

http://docstore.mik.ua/orelly/perl3/tk/ch09_21.htm
code:

use Tk;

$mw = MainWindow->new;
$mw->title("Quick Draw");

$f = $mw->Frame(-relief => 'groove',
-bd => 2,
-label => "Draw:")->pack(-side => 'left', -fill => 'y');
$draw_item = "rectangle";
$f->Radiobutton(-variable => \$draw_item,
-text => "Rectangle",
-value => "rectangle",
-command => \&bind_start)->pack(-anchor => 'w');
$f->Radiobutton(-variable => \$draw_item,
-text => "Oval",
-value => "oval",
-command => \&bind_start)->pack(-anchor => 'w');
$f->Radiobutton(-variable => \$draw_item,
-text => "Line",
-value => "line",
-command => \&bind_start)->pack(-anchor => 'w');
$f->Label(-text => "Line Width:")->pack(-anchor => 'w');
$thickness = 1;
$f->Entry(-textvariable => \$thickness)->pack(-anchor => 'w');

$c = $mw->Scrolled("Canvas", -cursor => "crosshair")->pack(
-side => "left", -fill => 'both', -expand => 1);
$canvas = $c->Subwidget("canvas");

&bind_start( );

MainLoop;

sub bind_start {
# If there is a "Motion" binding, we need to allow the user
# to finish drawing the item before rebinding Button-1
# this fcn gets called when the finish drawing the item again
@bindings = $canvas->bind("<Motion>");
return if ($#bindings >= 0);

if ($draw_item eq "rectangle"||$draw_item eq "oval"||$draw_item eq "line") {
$canvas->bind("<Button-1>", [\&start_drawing, Ev('x'), Ev('y')]);
}
}

sub start_drawing {
my ($canv, $x, $y) = @_;
$x = $canv->canvasx($x);
$y = $canv->canvasy($y);

# Do a little error checking
$thickness = 1 if ($thickness !~ /[0-9]+/);

if ($draw_item eq "rectangle") {
$canvas->createRectangle($x, $y, $x, $y,
-width => $thickness, -tags => "drawmenow");
} elsif ($draw_item eq "oval") {
$canvas->createOval($x, $y, $x, $y,
-width => $thickness, -tags => "drawmenow");
} elsif ($draw_item eq "line") {
$canvas->createLine($x, $y, $x, $y,
-width => $thickness, -tags => "drawmenow");
}

$startx = $x; $starty = $y;
# Map the Button-1 binding to &end_drawing instead of start drawing
$canvas->bind("<Motion>", [\&size_item, Ev('x'), Ev('y')]);
$canvas->bind("<Button-1>", [\&end_drawing, Ev('x'), Ev('y')]);
}

sub size_item {
my ($canv, $x, $y) = @_;
$x = $canv->canvasx($x);
$y = $canv->canvasy($y);

$canvas->coords("drawmenow", $startx, $starty, $x, $y);
}

sub end_drawing {
my ($canv, $x, $y) = @_;
$x = $canv->canvasx($x);
$y = $canv->canvasy($y);

# finalize the size of the item, and remove the tag from the item
$canvas->coords("drawmenow", $startx, $starty, $x, $y);
$canvas->dtag("drawmenow");

# remove motion binding.
$canvas->CanvasBind("<Motion>", "");
&bind_start( );
}

Anonymous  Jul 01, 2010 
Printed Page 586
bottom of page

% ppm install Tk - fails as there is no longer a Tk ppm package to install.

James Massoni  Mar 03, 2012 
Printed Page 717, 737
"after method" nad "repeat method" entries

Both the "after method" and "repeat method" entries in the index at the back of the 11/04 printing refer the reader to page 287, but there is no material describing the after() and/or repeat() methods of the MainWindow on this page.

In fact, a search of Chapter 15 failed to find such material either, other than a brief mention of their existence under TIMER_EVENTS on page 357.

I finally stumbled on some documentation for these methods in Chapter 13 on pages 305-306. The index should be updated accordingly, and ideally the TIMER_EVENTS sub-paragraph should refer to the Chapter 13 material too.


Anonymous