无涯教程-Tk - 图片组件

92 阅读1分钟

图像小部件用于创建和处理图像。创建图像的语法如下-

image create type name options

在上面的语法中,类型是照片或位图,名称是图像标识符。

图片参数

下表中列出了可用于图像创建的选项-

Sr.No. Syntax & Remark
1

-file fileName

图像文件名的名称。

2

-height number

用于设置小部件的高度。

3

-width number

设置小部件的宽度。

4

-data string

图片以64为基数的编码字符串。

图像小部件的一个简单示例如下所示-

#!/usr/bin/wish

image create photo imgobj -file "/Users/rajkumar/Desktop/F Drive/pictur/vb/Forests/ 680049.png" -width 400 -height 400 pack [label .myLabel] .myLabel configure -image imgobj

当无涯教程运行上面的程序时,将获得以下输出-

Image Example

下表列出了可用的图像函数-

Sr.No. Syntax & Remark
1

image delete imageName

可视地从内存和相关小部件中删除图像。

2

image height imageName

返回图像的高度。

3

image width imageName

返回图像的宽度。

4

image type imageName

返回图像的类型。

5

image names

返回内存中的图像列表。

下面显示了一个使用上述图像窗口小部件命令的简单示例-

#!/usr/bin/wish

image create photo imgobj -file "/Users/rajkumar/images/680049.png" -width 400 -height 400 pack [label .myLabel] .myLabel configure -image imgobj puts [image height imgobj] puts [image width imgobj] puts [image type imgobj] puts [image names] image delete imgobj

一旦执行" image delete imgobj"命令,该图像将通过视觉方式从内存中删除。在控制台中,输出将如下所示:

400
400
photo
imgobj ::tk::icons::information ::tk::icons::error ::tk::icons::
warning ::tk::icons::question

参考链接

www.learnfk.com/tcl-tk/tk-i…