📅  最后修改于: 2020-10-16 06:35:32             🧑  作者: Mango
图像小部件用于创建和处理图像。创建图像的语法如下-
image create type name options
在上面的语法中,类型是照片或位图,名称是图像标识符。
下表中列出了可用于图像创建的选项-
Sr.No. | Syntax & Description |
---|---|
1 |
-file fileName The name of the image file name. |
2 |
-height number Used to set height for widget. |
3 |
-width number Sets the width for widget. |
4 |
-data string Image in base 64 encoded string. |
图像小部件的一个简单示例如下所示-
#!/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
当我们运行上面的程序时,我们将获得以下输出-
下表列出了可用的图像函数-
Sr.No. | Syntax & Description |
---|---|
1 |
image delete imageName Deletes the image from memory and related widgets visually. |
2 |
image height imageName Returns the height for image. |
3 |
image width imageName Returns the width for image. |
4 |
image type imageName Returns the type for image. |
5 |
image names Returns the list of images live in memory. |
下面显示了一个使用上述图像小部件命令的简单示例-
#!/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