Tk - Canvas Image Widget


Advertisements

Image widget is used to create a displayed image item. An image can be created from a GIF, PNG, PPM, PGM, or X-Bitmap image. The syntax for image widget is shown below.

canvasName create image x y options

x and y set the location of a bitmap.

Option

The option available for the image widget are listed below in the following table −

Sr.No. Syntax & Description
1

-image imageName

The variable that holds image to display.

A simple example for image widget is shown below −

#!/usr/bin/wish

canvas .myCanvas -background red -width 100 -height 100 
pack .myCanvas
set myImage [image create photo]
$myImage read "/Users/myImages/myImage1.png"
.myCanvas create image 50 50 -image $myImage

When we run the above program, we will get the following output −

Canvas Image Example
tk_canvas_widgets.htm
Advertisements