내 응용 프로그램에서 한 번 클릭하면 원이 캔버스에 그려집니다. 더블 클릭하면 최근에 추가 된 점이 다각형에 연결됩니다.캔버스 항목에 Perl Tk 바인딩
새로운 원 위치를 클릭 한 점 (기존 점)의 중심으로 조정해야합니다. 기존 점 내부를 클릭하면 새로운 점이 기존 점과 일치합니다.
원과 전체 캔버스를 클릭 할 때 별도의 콜백을 설정하려고했지만 하나씩 호출했습니다. 그리고 원 클릭에 대한 콜백은 더블 클릭 후 호출됩니다 ...
이벤트 전파를 중지 할 수있는 방법이 있습니까? 내부 또는 기존 타원형의 외부를 클릭하면 확인
use strict;
use Tk;
my $countries = [];
push(@$countries, []);
my $mw = MainWindow->new;
$mw->title("Graph colorer");
$mw->minsize(600, 600);
$mw->resizable(0, 0);
my $canvas = $mw->Canvas(-background => 'white')->pack(-expand => 1,
-fill => 'both');
$canvas->bind('point', "<Button-1>", [ \&smart_point, Ev('x'), Ev('y') ]);
$canvas->Tk::bind("<Button-1>", [ \&append_point, Ev('x'), Ev('y') ]);
$canvas->Tk::bind("<Double-Button-1>", [ \&draw_last_country ]);
sub append_point {
my ($canv, $x, $y) = @_;
my $last_country = $countries->[-1];
my ($canvx, $canvy) = ($canv->canvasx($x), $canv->canvasy($y));
push(@$last_country, $canvx, $canvy);
$canv->createOval($canvx-5, $canvy-5, $canvx+5, $canvy+5, -tags => 'point',
-fill => 'green');
print "pushed (x,y) = ", $canvx, ", ", $canvy, "\n";
}
sub draw_last_country {
my $canv = shift;
$canv->createPolygon($countries->[-1]);
push(@$countries, []);
}
sub smart_point {
my $canv = shift;
my $id = $canv->find('withtag', 'current');
my ($x1, $y1, $x2, $y2) = $canv->coords($id);
print "clicked (x,y) = ", ($x2-$x1)/2, ", ", ($y2-$y1)/2, "\n";
}
MainLoop;