0

So i made a simple input(), slapped in a background with bgpic, and made so that the thing user wrote in input will work as text on the window, and it works. Is there any way so i can save the contents of the window to my pc without screenshots and cropping it?

Defframe
  • 21
  • 2

1 Answers1

1

I just had a rollercoaster of discovery with this exact problem! I ended up using the properties of turtle as a tkinter canvas to save it to a postscript. Then I used Pillow to convert the .ps to a .png. Here is the code I ended with:

import turtle
from PIL import Image

t = turtle.Turtle()
draw_stuff()

# Save as a postscript:
canvas = t.getscreen().getcanvas()
canvas.postscript(file="myfile.ps")

# Convert to a png:
img = Image.open('myfile.ps')
img.save('myfile.png')

For further information here are my posted questions: This shows how to convert it to a .ps:

How can I save a Turtle object (turtle.py) as a .png or .jpg in Python 3?

This shows how to convert it to a .png using PIL. NOTE: If you go to this link and look at the pictures, you should see an error just like the one you got.

How can I convert a .ps file into a .png file?

Feel free to ask any questions, especially about any problems you encounter with Ghostscript or PATH. Hope this helps!

How to fix the OS Error: Ghostscript not found in paths: First. make sure you've downloaded ghostscript. Here is the link to download the most recent version:

https://www.ghostscript.com/download/gsdnld.html

Once downloaded, go to your file explorer then open C:\Windows\Program Files (x86)\gs. (You may have to click view then check the hidden files box at the top of the interface) Then open gs9.52 and click the folder "bin". Copy the file path, it should be:

C:\Program Files (x86)\gs\gs9.52\bin

Last step- you need to add that file path to your system's PATH. Here is a great article, just follow these instructions:

https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

Once you add the file path to your system's PATH, you may need to restart your PC before it works. Then run the code you wrote using Pillow and the error should be gone. Let me know if there are any more problems.

InstaK0
  • 342
  • 3
  • 9
  • Ok, so i saved the screen as .ps and when i used this code : from PIL import Image turtle_img = Image.open("turtle_img.ps") turtle_img.save("turtle_img", "png") it gives me an error : – Defframe May 28 '20 at 18:22
  • Traceback (most recent call last): File "C:/Users/Defframe/Desktop/pythonprojects/baddesign.py", line 50, in turtle_img.save("turtle_img", "png") File "C:\Users\Defframe\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2100, in save self._ensure_mutable() File "C:\Users\Defframe\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 617, in _ensure_mutable – Defframe May 28 '20 at 18:22
  • self._copy() File "C:\Users\Defframe\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 610, in _copy self.load() File "C:\Users\Defframe\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\EpsImagePlugin.py", line 332, in load self.im = Ghostscript(self.tile, self.size, self.fp, scale) File "C:\Users\Defframe\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\EpsImagePlugin.py", line 134, in Ghostscript raise OSError("Unable to locate Ghostscript on paths") OSError: Unable to locate Ghostscript on paths – Defframe May 28 '20 at 18:23
  • help please am dubm – Defframe May 28 '20 at 18:28
  • I had the same problem. Tip- edit your original post and add follow up questions/explanations of what you've tried/pictures if you want more help. Then add a comment directing me to the post. I changed my answer to include more information – InstaK0 May 28 '20 at 18:54
  • Are you on a windows device? – InstaK0 May 28 '20 at 18:58
  • yes, windows @instak0 – Defframe May 28 '20 at 19:01
  • Okay I'm adding information to my post, just follow along and you should be good – InstaK0 May 28 '20 at 19:03
  • It finally worked, thank you so much!! – Defframe May 28 '20 at 19:29