1

my perl code looks like this:

#!/usr/bin/env perl

use strict;
use warnings;
use Tk;

my $mw = Tk::MainWindow->new();

$mw->overrideredirect(1);

my $canvas = $mw->Canvas(
    -bg => 'white',
    -width => 410,
)->pack(-fill => 'both', -expand => 1);


my $rect_filled = $canvas->createRectangle(
    0, 0, 360, 100,
    -outline => '#C0C0C0',
    -fill => '#FFEC73',
);
$canvas->bind( $rect_filled, '<Enter>' => sub{
    $canvas->itemconfigure( $rect_filled,
        -outline => '#E0E0E0',
        -fill => '#0000ff',
    );
});
$canvas->bind( $rect_filled, '<Leave>' => sub{
    $canvas->itemconfigure( $rect_filled,
        -outline => '#C0C0C0',
        -fill => '#FFEC73',
    );
});


$mw->MainLoop();

If I run this code, i can see the yellow rectangle. But, when I move the mouse into the canvas from above, the ENTER-event comes only after ~30 pixels, seen in the screenshot.

canvas no enter event canvas enter event

It seems as if the titlebar is still above the canvas.

How can I stop this behavior so that the ENTER-event is also raised from the coordinates (0,0)?

-- Update for question:

  • Debian 8.11
  • Gnome 3.14.1
  • Perl 5.20.2
  • Tk 804.032
1
  • 1
    It does not seem to be a problem with Perl. If I convert your script to a Tcl script it shows the same behavior. Commented Dec 30, 2020 at 13:00

1 Answer 1

2

I've found a workaround after read this:

https://metacpan.org/pod/distribution/Tk/pod/Wm.pod#BUGS

#!/usr/bin/env perl

use strict;
use warnings;
use Tk;

my $mw = Tk::MainWindow->new();

# $mw->overrideredirect(1); #

my $canvas = $mw->Canvas(
    -bg => 'white',
    -width => 410,
)->pack(-fill => 'both', -expand => 1);


my $rect_filled = $canvas->createRectangle(
    0, 0, 360, 100,
    -outline => '#C0C0C0',
    -fill => '#FFEC73',
);
$canvas->bind( $rect_filled, '<Enter>' => sub{
    $canvas->itemconfigure( $rect_filled,
        -outline => '#E0E0E0',
        -fill => '#0000ff',
    );
});
$canvas->bind( $rect_filled, '<Leave>' => sub{
    $canvas->itemconfigure( $rect_filled,
        -outline => '#C0C0C0',
        -fill => '#FFEC73',
    );
});

# workarround, delay call overrideredirect(1)
$mw->after( 1, sub{
    $mw->overrideredirect(1);
    $mw->withdraw();
    $mw->deiconify();
    print "set\n";
});

$mw->MainLoop();

But is this the right way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.