鍍金池/ 教程/ Python/ TK圖片
TK窗口管理器
TK特殊變量
TK 大型Widget
TK Widget概述
TK事件
TK選擇Widget
TK字體
Tk Canvas Widget
Tk教程
TK 基本W(wǎng)idget
TK幾何圖形管理器
TK Widget布局
TK環(huán)境設(shè)置
TK圖片

TK圖片

圖像小部件,用于創(chuàng)建和處理圖像。創(chuàng)建圖像的語(yǔ)法如下。

image create type name options

另外,在上述的語(yǔ)法類型是照片、位圖或名稱是圖像標(biāo)識(shí)符。

選項(xiàng)

可用于圖像的選項(xiàng)創(chuàng)建列于下表中。

SN 語(yǔ)法 描述
1 -file fileName 圖像文件名的名稱。
2 -height number 用于設(shè)置部件widget的高度。
3 -width number 設(shè)置widget的寬度。
4 -data string 圖像中基本64編碼字符串。

一個(gè)簡(jiǎn)單圖像小部件的例子如下所示。

#!/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 

當(dāng)我們運(yùn)行上面的程序,會(huì)得到下面的輸出。

Image Example

可用函數(shù)用于圖像列于下表中。

SN 語(yǔ)法 描述
1 image delete imageName 刪除從存儲(chǔ)器和相關(guān)的小窗口在視覺上的圖像。
2 image height imageName 返回高度的圖像。
3 image width imageName 返回圖像的寬度。
4 image type imageName 返回圖像的類型。
5 image names 返回存在存儲(chǔ)器中的圖像列表。

一個(gè)簡(jiǎn)單的例子,使用上面圖像小部件的命令如下所示。

#!/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”命令執(zhí)行刪除。在控制臺(tái),輸出會(huì)像下面。

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

上一篇:TK窗口管理器下一篇:TK特殊變量