Leser: 1
6 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/env perl use strict; use warnings; use Tk; $|++; my $data = { pressed => 0, }; my $mw = MainWindow->new(); my $canvas = $mw->Canvas(-width => 200, -height => 200)->pack(); $canvas->CanvasBind('<ButtonPress>', sub {$data->{pressed} = 1; print "pressed\t";}); $canvas->CanvasBind('<ButtonRelease>', sub {$data->{pressed} = 0; print "released\n";}); my @items; for my $x (1 .. 4) { my $x1 = $x * 25; my $y1 = $x1; my $x2 = $x1 + 25; my $y2 = $y1 + 25; $items[$x - 1] = $canvas->createRectangle($x1, $y1, $x2, $y2, -fill => 'red', -width => 0); } $canvas->bind($items[$_], '<Enter>', sub {if ($data->{pressed}) {print "wtf\t"}}) for 0 .. 3; MainLoop();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use strict;
use warnings;
use Tk;
$|++;
my $data = {
pressed => 0,
};
my $mw = MainWindow->new();
my $canvas = $mw->Canvas(-width => 200, -height => 200)->pack();
my @items;
for my $x (1 .. 4) {
my $x1 = $x * 25;
my $y1 = $x1;
my $x2 = $x1 + 25;
my $y2 = $y1 + 25;
$items[$x - 1] = $canvas->createRectangle($x1, $y1, $x2, $y2, -fill => 'red', -width => 0);
}
$canvas->Tk::bind( '<B1-Motion>', [\&b1_motion,Tk::Ev('x'),Tk::Ev('y')]) for 0 .. 3;
MainLoop();
sub b1_motion{
my ($c,$x,$y) = @_;
my $item_id = $c->find('overlapping',$x,$y,$x,$y);
$item_id = defined $item_id ? $item_id->[0] : '';
print "processing item $item_id\n" if $item_id;
}
QuoteEnter and Leave events trigger for an item when it becomes the current item or ceases to be the current item; note that these events are different than Enter and Leave events for windows.
1
2
3
4
5
6
use Tk;
my $mw = tkinit;
$mw->Entry()->pack->bind('<Enter>',sub{print"entered\n"}) for (0..5);
MainLoop;
1
2
3
4
5
6
/*
* Check whether or not a button is down. If so, we'll log entry
* and exit into and out of the current item, but not entry into
* any other item. This implements a form of grabbing equivalent
* to what the X server does for windows.
*/
6 Einträge, 1 Seite |