1

I tried the following which I found on this site:

from turtle import *
import canvasvg

def saveImg():
    name = input("What would you like to name it? ")
    nameSav = name + ".svg"
    ts = getscreen().getcanvas()
    canvasvg.saveall(nameSav, ts)

penup()
goto(-60,-225)
pendown()
left(90)
hideturtle()
speed(0)
forward(20)

saveImg()

This is the error message I got:

File "test.py", line 18, in <module>
    saveImg()
  File "test.py", line 8, in saveImg
    saveall(nameSav, ts)
NameError: name 'saveall' is not defined

I know that canvasvg includes a definition for saveall(), so I don't see why it cannot find this function.

Please help and try to be simple in your answers as I just started coding ;)

martineau
  • 119,623
  • 25
  • 170
  • 301
Nina
  • 13
  • 3

1 Answers1

1

If canvasvg includes saveall then you must do canvasvg.saveall(). If saveall were inside turtle, then you would have it because you did from turtle import *.

Your other option is changing import canvasvg to from canvasvg import * but I don't recommend it.


UPDATE:

I tried to run your script and I noticed that, actually, canvasvg contains two different submodules: canvasvg.canvasvg and canvasvg.setup. I don't know why. However, you can just replace:

import canvasvg

With:

from canvasvg import canvasvg

And then you can call canvasvg.saveall().

However, I discovered that there is a bug in the last Python 3 version of canvasvg. Thus, you should either wait for canvasvg developers to fix it, or you can use the Python 2 version of canvasvg.

If you want to switch to Python 2, you should only change input to raw_input. I tested and it seems to work flawlessly.

Community
  • 1
  • 1
William
  • 2,695
  • 1
  • 21
  • 33
  • Sorry, I posted a work in progress of the code from when I tried to make it work. I actually used canvasvg.saveall() at the beginning without success. Do you have any other recommendations? Thanks – Nina Nov 07 '15 at 20:09
  • What is the real error then? The error posted in the question clearly shows that `saveall()` was used instead of `canvasvg.saveall()` :) – William Nov 07 '15 at 20:39
  • I did run your script to see the error and I updated the answer :) – William Nov 07 '15 at 20:57
  • Thanks a lot. You're a real help. I'll try and see if my complete program runs in Python 2. – Nina Nov 08 '15 at 21:41
  • I tried both, using python 3 and 2 on after the other with the alterations you proposed but I still get the following error message: Warning (from warnings module): File "C:\Python27\lib\site-packages\canvasvg.py", line 147 warn("Items of type '%s' are not supported." % itemtype) UserWarning: Items of type 'image' are not supported. – Nina Nov 08 '15 at 22:00