You need to understand how the canvas tag system works. The dragster IS NOT an object, so it cannot have methods. I could make it into object, with some package code, but in general, "items" on a canvas, are elements of the canvas widget.
Your second question is about canvas tags also.
There is a difference between the canvas's bind and the normal Tk::bind. The canvas's bind will let you bind to a tag. If you look at each canvas item's creation, you will see it is given a tag(s). This is the basis of the canvas's power, because you can do all sorts of trickery with addtag and deltag to change an item's tags dynamically. So you can do things like setup a callback when a mouse enters any item with a certain tag. Like this:
#!/usr/bin/perl
use Tk;
my $mw = MainWindow->new();
$mw->geometry("600x400+100+100");
$canvas = $mw->Canvas(width => 600, height => 400)->pack();
$canvas->Tk::bind("<Button-1>", [ \&print_xy, Ev('x'), Ev('y') ]);
# This draws half of an oval
$oval = $canvas->createOval(100,100,200,250,-fill => 'white',-tags =>
+"blue");
$canvas->Tk::bind("<Button-3>", sub {$canvas->itemconfigure($oval,-fil
+l => "red")});
$canvas->bind('blue', '<Enter>',
sub { $canvas->itemconfigure("blue", -fill => "blue"); } )
+;
# sub {exit});
# When the mouse is not over, color it black.
$canvas->bind("blue", "<Leave>",
sub { $canvas->itemconfigure("blue", -fill => "black"); });
#$tw->tagBind('tag','<Enter>',sub{$overtag=1});
MainLoop;
sub print_xy {
print "@_\n";
my ($canv, $x, $y) = @_;
print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\n"
+;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.