Here's a little proof-of-concept of one way to implement a "pen" in Canvas.
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my @lines;
my $mw = MainWindow->new;
my $c = $mw->Canvas(-width => 900, -height => 900,)->pack(-side => 'bo
+ttom');
$mw->Button(-text => $_->[0], -command => $_->[1])->pack(-side => 'rig
+ht') for
[ Exit => sub { $mw->destroy } ],
[ 'Clear Last' => sub { pop @lines; redraw() } ],
[ 'Clear All' => sub { @lines = (); redraw() } ];
$c->Tk::bind('<1>' => sub
{
push @lines, [ &xy ];
redraw();
$c->Tk::bind('<Motion>' => sub { push @{ $lines[-1] }, &xy; redraw()
+ } );
} );
$c->Tk::bind('<ButtonRelease-1>' => sub { $c->Tk::bind('<Motion>' => '
+') } );
MainLoop;
sub xy { $_[0]->XEvent->x, $_[0]->XEvent->y }
sub redraw
{
$c->delete('pen');
@$_ >= 4 and $c->createLine(@$_, -smooth => 1, -width => 5, -tag =>
+'pen')
for @lines;
}
-
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.
|