Tk - 影像



image 小部件用於建立和操作影像。建立影像的語法如下:

image create type name options

在以上語法中,type 為 photo 或 bitmap,name 為影像識別符號。

選項

image create 可用的選項在下面的表格中列出:

序號 語法和描述
1

-file fileName

影像檔名。

2

-height number

用於設定小部件的高度。

3

-width number

設定小部件的寬度。

4

-data string

Base64 編碼的字串形式的影像。

image 小部件的一個簡單示例如下所示:

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

image 可用的函式在下面的表格中列出:

序號 語法和描述
1

image delete imageName

從記憶體中刪除影像,並從視覺上刪除相關的視窗部件。

2

image height imageName

返回影像的高度。

3

image width imageName

返回影像的寬度。

4

image type imageName

返回影像的型別。

5

image names

返回記憶體中存在的影像列表。

使用以上 image 小部件命令的一個簡單示例如下所示:

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