圖像小部件,用于創(chuàng)建和處理圖像。創(chuàng)建圖像的語法如下。
image create type name options
另外,在上述的語法類型是照片、位圖或名稱是圖像標(biāo)識符。
可用于圖像的選項創(chuàng)建列于下表中。
| SN | 語法 | 描述 |
|---|---|---|
| 1 | -file fileName | 圖像文件名的名稱。 |
| 2 | -height number | 用于設(shè)置部件widget的高度。 |
| 3 | -width number | 設(shè)置widget的寬度。 |
| 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
當(dāng)我們運行上面的程序,會得到下面的輸出。
可用函數(shù)用于圖像列于下表中。
| SN | 語法 | 描述 |
|---|---|---|
| 1 | image delete imageName | 刪除從存儲器和相關(guān)的小窗口在視覺上的圖像。 |
| 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”命令執(zhí)行刪除。在控制臺,輸出會像下面。
400 400 photo imgobj ::tk::icons::information ::tk::icons::error ::tk::icons::warning ::tk::icons::question