can't read "filename": no such variable
    while executing
"string length $filename"
    invoked from within
"if {[string length $filename]} {
## Ensure that the window is on top of everything else, so as not to get
## white ranges in the image, due to overlap..."
    (in namespace eval "::request" script line 1)
    invoked from within
"namespace eval ::request $script"
    ("::try" body line 12)

OUTPUT BUFFER:

if {[string length $filename]} { ## Ensure that the window is on top of everything else, so as not to get ## white ranges in the image, due to overlapped portions of the window with ## other windows... raise [winfo toplevel $canvas] update set border [expr {[$canvas cget -borderwidth] + [$canvas cget -highlightthickness]}] set view_height [expr {[winfo height $canvas]-2*$border}] set view_width [expr {[winfo width $canvas]-2*$border}] foreach {x1 y1 x2 y2} [$canvas bbox all] {break} set x1 [expr {int($x1-10)}] set y1 [expr {int($y1-10)}] set x2 [expr {int($x2+10)}] set y2 [expr {int($y2+10)}] set width [expr {$x2-$x1}] set height [expr {$y2-$y1}] namespace eval ::MainWindow::images {} image create photo ::MainWindow::images::windowImage \ -height $height -width $width ## Arrange the scrollregion of the canvas to get the whole window visible, ## so as to grab it into an image... set scrollregion [$canvas cget -scrollregion] set xscrollcommand [$canvas cget -xscrollcommand] set yscrollcommand [$canvas cget -yscrollcommand] $canvas configure -xscrollcommand {} $canvas configure -yscrollcommand {} set grabbed_x $x1 set grabbed_y $y1 set image_x 0 set image_y 0 while {$grabbed_y < $y2} { while {$grabbed_x < $x2} { $canvas configure -scrollregion [list $grabbed_x $grabbed_y \ [expr {$grabbed_x + $view_width}] [expr {$grabbed_y + $view_height}]] update ## Take a screenshot of the visible canvas part... image create photo ::MainWindow::images::tmp_image \ -format window -data $canvas ## Copy the screenshot to the target image... ::MainWindow::images::windowImage copy ::MainWindow::images::tmp_image \ -to $image_x $image_y -from $border $border incr grabbed_x $view_width incr image_x $view_width } set grabbed_x $x1 set image_x 0 incr grabbed_y $view_height incr image_y $view_height } $canvas configure -scrollregion $scrollregion $canvas configure -xscrollcommand $xscrollcommand $canvas configure -yscrollcommand $yscrollcommand switch -glob -- [string tolower $filename] { *.png {set format png} *.jpg - *.jpeg {set format jpeg} *.bmp {set format bmp} default {set format bmp} } ::MainWindow::images::windowImage write $filename -format $format image delete ::MainWindow::images::windowImage \ ::MainWindow::images::tmp_image }