Before you can display a graphic in Tk, you must first create a Tk image. To accomplish this, Tk provides the image
command. This command allows you to create, delete, and query the keywords for any of the supported image types. The built-in image types are bitmap (two color graphics) and photo. The photo types as shipped in the base distribution are PPM/PGM and GIF.
Based on the keyword used the image command takes several syntactic forms. The syntax and keywords are as follows:
Keyword |
Interpretation |
---|---|
|
Creates an image and a command with the same name. |
|
Deletes the named image. |
|
Returns a decimal string containing the height of the image in pixels. |
|
Returns a Boolean value indicating if the named image provided is currently in use. |
|
Returns a list containing the names of all created images. |
|
Returns the type of image as referenced by name. |
|
Returns a lost containing all valid image types. |
|
Returns a decimal string containing the width of the image in pixels. |
To complete the following example you will need to have a GIF file to select. Please locate the file tcllogo.gif
in your Tcl installation in the demos/Tk8.5/images
directory and copy it into your working path.
In the following example we will create an image and display it within a label. Enter the following commands:
1 % image create photo image1 -file tcllogo.gif
.image1
2 % label .l -image image1
.l
3 % pack .l
At this point, your window should look like the following:
3.141.42.116