Tk - Canvas Image Widget


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.


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

Sr.No. Syntax & Description

-image imageName

The variable that holds image to display.

A simple example for image widget is shown below −


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