I am trying to export the content of a canvas to a GIF file (or
whatever format possible).
I got an example from wiki.tcl.tk but it isn't working for me. I am
using ActiveState Tcl8.6 and my code is the following:
package require Tk
package require Img
set c [canvas .c]
pack $c
$c create rectangle 10 20 30 40
set img [image create photo -format window -data .c]
$img write test.gif -format GIF
When executed, it returns this error:
$ ./tst.tcl
Window ".c" is not mapped
while executing
"image create photo -format window -data .c"
invoked from within
"set img [image create photo -format window -data .c]"
(file "./tst.tcl" line 13)
Anyone can help me understand what a "mapped window" is ?
Thanks in advance.
-- Daniel <dan...@contratake.com.br>
In simple terms one that is visible on the screen. Tcl/Tk uses a 'lazy
eval' strategy to minimize unneccessary processing. You need to add an
'update idletasks' just before the image create:
package require Tk
package require Img
set c [canvas .c]
pack $c
$c create rectangle 10 20 30 40
update idletasks;# Flush pending events, in this case mapping the window.
set img [image create photo -format window -data .c]
$img write test.gif -format GIF
>
>
> Thanks in advance.
>
> -- Daniel <dan...@contratake.com.br>
>
--
Robert Heller -- 978-544-6933 / hel...@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
Hi Robert.
I tried what you suggested, but got the same error.
$ cat tst.tcl
#!/cygdrive/c/Tcl/bin/tclsh86.exe
package require Tk
package require Img
set c [canvas .c]
pack $c
wm deiconify .
$c create rectangle 10 20 30 40
update idletasks
set img [image create photo -format window -data .c]
$img write test.gif -format GIF
$ ./tst.tcl
Window ".c" is not mapped
while executing
"image create photo -format window -data .c"
invoked from within
"set img [image create photo -format window -data .c]"
(file "./tst.tcl" line 13)
-- Daniel
I just removed the 'idletasks' from the update, and it worked! =)
Thank you.