Username: Password:

Perl/TkFAQ-11.5.怎样调整画布中线条的位置?
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00:00:00


  原文:

  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 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’);。另外,这个方法可是对画布中各种元件都有用的哟!)

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅