Tk Source Code

Artifact [473b3d16]
Login

Artifact 473b3d169670d83ef073b7fc89f39c4ea1fda1d1c476582e15d82ba3999bdf81:

Attachment "737abf4523 - text widget has terrible performance with image create.tcl" to ticket [737abf45] added by fvogel 2024-01-09 22:05:59.

# 737abf4523 - text widget has terrible performance with image create

package require Tk

set IMAGE [lindex [image names] 0]
pack [text .t]
focus .t
bind .t	<Escape>	{exit 0}
update

set HowMany 5000

proc RunTextMode {} {
    global IMAGE
    for {set i 1} {$i <= $::HowMany} {incr i} {
        .t insert end "line $i: "
        .t image create end -image $IMAGE
        .t insert end " :$i\n"
    }
}
proc RunButtonMode {} {
    global IMAGE
    for {set x 1} {$x <= $::HowMany} {incr x} {
        button .t.b$x -text "button $x" -width 160 -image $IMAGE -compound left
        #button .t.b$x -font {Freesans 12} -text "button $x" -width 160 -image $IMAGE -compound left
        pack .t.b$x
        .t window create end -window .t.b$x
        .t insert end "\n"
    }
}

set begin [clock milliseconds]
#Uncomment and run one of these
RunTextMode
#RunButtonMode
update
set end [clock milliseconds]

puts "[expr {$end - $begin}] ms"