变量追踪:
某一变量的变化触发回调。
#!/usr/bin/perl -w
use strict;
use Tk::widgets qw/ Trace /;
my $variable = 1;
$MW = Tk::MainWindow->new;
$MW->traceVariable(\$variable , 'w' => [\&callbackfunction]);
Tk::MainLoop;
sub callbackfunction
{
print "====the variable is changed\n";
}
类线程的实现:
在callbackfunction函数中循环,做你想做的事情,然后调用$MW->update,执行另外的事件,可以达到类似线程的效果。
sub callbackfunction
{
print "====the variable is changed\n";
while(1){
print "to do you want to";
$MW->update;
}
}