Username: Password:

Perl/TkFAQ-11.3.怎样在画布中显示图片?
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00:00:00


  原文:

  11.3. Display an Image?

  Just as for the other widget types there is a two step process of first getting a "Photo" handle on the file of interest. For the Canvas (unlike the other widgets) one then makes a call to create an image as in the following example where ’IMG’ is the Photo handle for a GIF file that comes distributed with the Tk kit (it just happens to be handled in this example via the scalar variable $img): #!/usr/bin/perl -w use strict; use Tk; my $main = new MainWindow; my $canvar = $main ->Canvas; $canvar->pack; my $file = ’demos/images/earth.gif’; my $img = $canvar->Photo( ’IMG’, -file => Tk->findINC($file) ); $canvar->create( ’image’,0,0, ’-anchor’ => ’nw’, ’-image’ => $img ); MainLoop; __END__

  译文:

  11.3. 怎样在画布中显示图片?

  就像在其他的组件中显示图片相同,需要两个步骤。首先是要产生一个指向需要显示的图片的Photo句柄;对于画布组件(不同于其他的组件),然后,就能够像下面的例子中那样,调用create方法来创建图像了。(其中的IMG是指向我们显示的GIF文档的Photo句柄名称,这里的GIF文档是Tk包自带的 ??在这个例子中,我们使用了一个标量$img来控制他):

  #!/usr/bin/perl -w

  use strict;

  use Tk;

  my $main = new MainWindow;

  my $canvar = $main ->Canvas;

  $canvar->pack;

  my $file = ’demos/images/earth.gif’;

  my $img =

  $canvar->Photo( ’IMG’,

  -file => Tk->findINC($file) );

  $canvar->create( ’image’,0,0,

  ’-anchor’ => ’nw’,

  ’-image’ => $img );

  MainLoop;

  __END__

  (译者注:其实这里的’IMG’相当于是这个Photo句柄的标签??是能够任意选择的,所以在使用时他能够等价于$img??也就是说在倒数第二行中,我们也能够使用-image=>’IMG’来代替。)

喜欢本文,那就收藏到:

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