Perl/TkFAQ-10.10.如何显示一个图像?

王朝perl·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

原文:

10.10. How do I display an image?

You will want to get a "Photo" handle on the file as in the following example where 'imggif' is the Photo handle for a gif file that is distributed with perl/Tk:

#!/usr/bin/perl -w use strict; use Tk; my $main = new MainWindow; $main ->Label(-text => 'Main')->pack; $main -> Photo('imggif', -file => "$Tk::tk_library/demos/images/earth.gif"); my $l = $main->Label('-image' => 'imggif')->pack; $main->Button(-text => 'close', -command => sub{destroy $main} )->pack(-side => 'left'); $main->Button(-text => 'exit', -command => [sub{exit}] )->pack(-side => 'right'); MainLoop;

(Canvas widgets are another story however see question a later question within this FAQ).

译文:

10.10. 如何显示一个图像?

要想显示一个图像文件(译者注:目前所能显示的图片格式,除了Bitmap和Pixmap外,好像只有:GIF和PPM/PGM),我们需要为这个文件创建一个Photo句柄。例如,在下面的例子中,’imggif’就是我们为一个GIF图像文件创建的Photo句柄(这个图片是Perl/Tk包中自带的)。

#!/usr/bin/perl -w

use strict;

use Tk;

my $main = new MainWindow;

$main ->Label(-text => 'Main')->pack;

$main -> Photo('imggif',

-file => "$Tk::library/demos/images/earth.gif");

my $l = $main->Label('-image' => 'imggif')->pack;

$main->Button(-text => 'close',

-command => sub{destroy $main}

)->pack(-side => 'left');

$main->Button(-text => 'exit',

-command => [sub{exit}]

)->pack(-side => 'right');

MainLoop;

(Canvas组件是另一种显示图片的方式,但是我们将在后面专门讨论。)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航