What does Ev mean in this context ?..........Ev is never defined nowhere in the source.....

Those are X window events. They are mentioned in perldoc Tk::bind under the Events section, but they are built so deep into the Tk windowing system, that it is probably in the Tcl c code, from which Perl/Tk is derived. If you look at perldoc Tk::Widget, you will see that every Tk widget has a $widget->pointerx (y) attribute. That is the x and y mouse pointer location relative to the widget itself...i.e. 0,0 is the widget's upper left corner. Tk bind has built in events, for the mouse and keypress activity, called Ev('x'), Ev('y'), Ev('k') and you can bind to those events. Additionally, most widgets will have a method to determine which widget element is located at any of it's pointerx and pointery locations. Here is a simple example:

#!/usr/bin/perl use warnings; use strict; use Tk; my $dx; my $dy; my $mw = MainWindow->new; $mw->geometry("700x600"); my $canvas = $mw->Canvas(-width => 700, -height => 565, -bg => 'black', -borderwidth => 3, -relief => 'sunken', )->pack; my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi +t(0)}) ->pack; my $dragster = $canvas->createRectangle(0, 20, 50, 75, -fill => 'red', -tags => ['move'], ); $canvas->bind('move', '<1>', sub {&mobileStart();}); $canvas->bind('move', '<B1-Motion>', sub {&mobileMove();}); $canvas->bind('move', '<ButtonRelease>', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $canvas->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $canvas->raise('current'); print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $canvas->XEvent; $canvas->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); print "MOVING-> $dx $dy\n"; my $color = $canvas->itemcget($dragster,'-fill'); print "color -> $color\n"; #or use bbox here for odd shapes.. bounding box my @coords = $canvas->coords($dragster); print "coords-> @coords\n"; } sub mobileStop{&mobileMove;}

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: I don't understand a piece of Perl/Tk code by zentara
in thread I don't understand a piece of Perl/Tk code by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.