Embedded Images

Tk 8.0 added embedded images that are much like embedded windows. They provide a more efficient way to add images than creating a canvas or label widget to hold the image. You can also put the same image into a text widget many times. Example 33-5 uses an image for the bullets in a bulleted list:

Example 33-5 Using embedded images for a bulleted list.
 proc BList_Setup { t imagefile } { global blist set blist(image) [image create photo -file $imagefile] $t tag configure bulletlist -tabs ".5c center 1c left" \ -lmargin1 0 -lmargin2 1c } proc BList_Item {t text {mark insert}} { global blist # Assume we are at the beginning of the line $t insert $mark \t bulletlist $t image create $mark -image $blist(image) $t insert $mark \t$text ...

Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.