Some kind of difficulty is that when you use "break" or "continue" - which are
described in Tk "bind" manual - those must be coded in tcl/tk language, and for
this $int->Eval("break") isn't going to work
IOW your script changes to this:
use Tcl::Tk;
my $int = Tcl::Tk->new();
my $mw = $int->mainwindow();
my $b = $mw->Text()->pack();
$b->bind('<Enter>' => 'puts this; break');
$b->bind('all','<Enter>' => sub {print "This shouldn't be printed\n";});
$int->MainLoop;
So in 'bind' you must specify tcl/tk script which contains tk's 'break'
If you need to execute some perl code and then break - then you need to split
perl code into separate sub, like this:
...
$b->bind('<Enter>' => 'some_perl_sub; break');
...
Let me know if I should help you with this part "some_perl_sub"
Regards,
Vadim
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Sunday, January 19, 2020 12:57 PM
To: [email protected]
Subject: Using break in callback function with Tcl::Tk
Hello everybody,
Does anybody know, how to use the tcl "break" function in a Tcl::Tk event
callback. I saw https://www.perlmonks.org/?node_id=1026146 but I cannot make
head or tail of it.
Here is my simple try, that doesn't work:
use Tcl::Tk;
my $int = Tcl::Tk->new();
my $mw = $int->mainwindow();
my $b = $mw->Text()->pack();
$b->bind('<Enter>' => \&enter);
$b->bind('all','<Enter>' => sub {print "This shouldn't be printed\n";});
$int->MainLoop;
sub enter {
print "hello\n";
eval {
$int->Eval('-code break');
};
}
Without the eval in the function enter, I get an error: "command bound to
event"..
Thanks in advance for any help,
Max
PS.: Appending a binding with "bind $w +command" works as follows ;-) :
$int->CreateCommand('ent',\&enter);
$b->bind('<Enter>' => '+ent');