| 您的位置:首页 > 文档 > perl > |
文章分类热门文章 |
Perl/Tk FAQ - 11.5. 如何调整画布中线条的位置?创建:2005-10-27 22:03:49 作者:Unlinux 来自: http://www.Unlinux.com 原文: 11.5. How do I redraw a line on a Canvas? By calling the ->coord method on the item as in the following example: #!/usr/bin/perl use Tk; $m = MainWindow->new; $c = $m -> Canvas; $i = $c -> create('line', 0,0 => 50,50 ); $c -> pack; $b = $m -> Button('-text' => 'extend', '-command' => sub{push_it($c,$i)}, )->pack; MainLoop; sub push_it { my ($canvas, $line) = @_; $canvas -> coords($line, 0,0 => 100,100 ); } Thanks to Christopher Dunn and Harry Bochner <bochner@das.harvard.edu> for providing this question and answer. 译文: 11.5. 如何调整画布中线条的位置? 这可以通过对这个元件(line)调用->coord方法来实现,例如: #!/usr/bin/perl use Tk; $m = MainWindow->new; $c = $m -> Canvas; $i = $c -> create('line', 0,0 => 50,50 ); $c -> pack; $m -> Button('-text' => 'extend', '-command' => sub{push_it($c,$i)}, )->pack; MainLoop; sub push_it { my ($canvas, $line) = @_; $canvas -> coords($line, 0,0 => 100,100 ); } 感谢Christopher Dunn和Harry Bochner提供了这个问题及答案! (译者注:其实对于线条的调整不仅限于位置,其它的各种属性都是可以的——使用itemconfigure方法来实现!有兴趣的朋友可以试试在上面的例子中的子程序的最后加上这样一行来看看效果如何:$canvas->itemconfigure($line,-width=>3,-fill= >'red',-arrow=>'both');。另外,这个方法可是对画布中各种元件都有用的哟!) 转载自:http://www.unlinux.com/doc/perl/20051027/4321.html 【评论】 【加入收藏夹】 【大 中 小】 【打印】 【关闭】 ※ 相关链接
|