原文:
10.2. How do I get a Button to actively change under my mouse pointer?
You should specify both an '-image' and an '-activeimage' configuration option either when calling the ->Button() method or in a later separate call to the ->configure() method.
Here is an example excerpted from the basic_demo script that comes with the Tk kit: #!/usr/local/bin/perl -w use Tk; $main = MainWindow->new; $QPBFile = "demos/images/QuitPB.xpm"; $QPBaFile = "demos/images/QuitPBa.xpm"; $QuitPB = $main->Pixmap('-file' => Tk->findINC("$QPBFile")); $QuitPBa = $main->Pixmap('-file' => Tk->findINC("$QPBaFile")); my $but = $main->Button('-image' => $QuitPB, '-activeimage' => $QuitPBa, '-command' => sub { $main->destroy } ) -> pack; MainLoop; __END__译文:
10.2. 如何设置按钮随鼠标指向的动态变化?
这需要在调用->Button()方法创建按钮的时候,或者是后来使用->configure()方法的时候,设定“-image”和“-activeimage”两个选项。
下面是从Tk包中的basic_demo脚本中摘录出来的一个例子:
#!/usr/local/bin/perl -w
use Tk;
$main = MainWindow->new;
$QPBFile = "demos/images/QuitPB.xpm";
$QPBaFile = "demos/images/QuitPBa.xpm";
$QuitPB = $main->Pixmap('-file' => Tk->findINC("$QPBFile"));
$QuitPBa = $main->Pixmap('-file' => Tk->findINC("$QPBaFile"));
my $but = $main->Button('-image' => $QuitPB,
'-activeimage' => $QuitPBa,
'-command' => sub { $main->destroy }
) -> pack;
MainLoop;
__END__