Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Window not mapped while creating image

78 views
Skip to first unread message

Daniel

unread,
May 19, 2011, 2:37:12 PM5/19/11
to
Hi folks,

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>

Robert Heller

unread,
May 19, 2011, 3:24:43 PM5/19/11
to

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



Daniel

unread,
May 19, 2011, 3:44:44 PM5/19/11
to
On 19 maio, 16:24, Robert Heller <hel...@deepsoft.com> wrote:
> Deepwoods Software        --http://www.deepsoft.com/

> ()  ascii ribbon campaign -- against html e-mail
> /\  www.asciiribbon.org  -- against proprietary attachments- Ocultar texto das mensagens anteriores -
>
> - Mostrar texto das mensagens anteriores -

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

Daniel

unread,
May 19, 2011, 3:47:43 PM5/19/11
to
> -- Daniel- Ocultar texto das mensagens anteriores -

>
> - Mostrar texto das mensagens anteriores -

I just removed the 'idletasks' from the update, and it worked! =)

Thank you.

0 new messages