toma has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know of good documentation or example code that uses Tk events?

It was difficult for me to discover that $e->X and friends did what I wanted.

It seems like the documentation of bind() could use a few more examples in perldoc Tk::bind. There wasn't much in O'Reilly's Mastering Tk along the lines of my code, either.

Am I missing something? Am I writing this code in an unusual way, and perhaps there is another way to do it that has examples in the documentation?

I have been able to find some interesting information by looking at tkBind.c in the pTk source code.

use strict; use warnings; use diagnostics; use Tk; my $mw= MainWindow->new; my $canvas= $mw->Canvas( -background => 'black', -width => '100', -height => '200', )->pack; $canvas->CanvasBind('<Motion>', \&print_coords); &MainLoop; sub print_coords { my ($evt) = @_; my $e= $evt->XEvent; print $e->X,',',$e->Y,' ',$e->x,',',$e->y,"\n"; }

It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re: Tk event examples?
by PodMaster (Abbot) on Nov 01, 2002 at 08:42 UTC
Re: Tk event examples?
by Zaxo (Archbishop) on Nov 01, 2002 at 08:30 UTC

    Does 'man n event' from the tcl/tk docs help? It doesn't go into the Perl-Tk interface, but the technical features of tk events are covered in a good bit of detail.

    After Compline,
    Zaxo

Re: Tk event examples?
by strat (Canon) on Nov 01, 2002 at 12:37 UTC
    Some time ago, I've written a little game because I wanted to play around a bit with Tk::Canvas. If you are interested in the code, goto(http://www.fabiani.net/)->Tips&Tricks->Downloads->Download von Käsekästchen

    Another help might be the widget(.bat) in the perl/bin-Path which contains a lot of Tk-examples. Although they are coded more in a way a Tcl programmer would write code, I've learned a lot by having a look at the code...

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"