Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:29:27+00:00 2026-06-15T05:29:27+00:00

I am new to Python and have been working with the turtle module as

  • 0

I am new to Python and have been working with the turtle module as a way of learning the language.

Thanks to stackoverflow, I researched and learned how to copy the image into an encapsulated postscript file and it works great. There is one problem, however. The turtle module allows background color which shows on the screen but does not show in the .eps file. All other colors, i.e. pen color and turtle color, make it through but not the background color.

As a matter of interest, I do not believe the import of Tkinter is necessary since I do not believe I am using any of the Tkinter module here. I included it as a part of trying to diagnose the problem. I had also used bgcolor=Orange rather than the s.bgcolor="orange".

No Joy.

I am including a simple code example:

# Python 2.7.3 on a Mac

import turtle
from Tkinter import *

s=turtle.Screen()
s.bgcolor("orange")

bob = turtle.Turtle()
bob.circle(250)

ts=bob.getscreen()
ts.getcanvas().postscript(file = "turtle.eps")

I tried to post the images of the screen and the .eps file but stackoverflow will not allow me to do so as a new user. Some sort of spam prevention. Simple enough to visualize though, screen has background color of orange and the eps file is white.

output produced from .eps file

I would appreciate any ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:29:28+00:00Added an answer on June 15, 2026 at 5:29 am

    Postscript was designed for making marks on some medium like paper or film, not raster graphics. As such it doesn’t have a background color per se that can be set to given color because that would normally be the color of the paper or unexposed film being used.

    In order to simulate this you need to draw a rectangle the size of the canvas and fill it with the color you want as the background. I didn’t see anything in the turtle module to query the canvas object returned by getcanvas() and the only alternative I can think of is to read the turtle.cfg file if there is one, or just hardcode the default 300×400 size. You might be able to look at the source and figure out where the dimensions of the current canvas are stored and access them directly.

    Update:

    I was just playing around in the Python console with the turtle module and discovered that what the canvas getcanvas() returns has a private attribute called _canvas which is a <Tkinter.Canvas instance>. This object has winfo_width() and winfo_height() methods which seem to contain the dimensions of the current turtle graphics window. So I would try drawing a filled rectangle of that size and see if that gives you what you want.

    Update 2:

    Here’s code showing how to do what I suggested. Note: The background must be drawn before any other graphics are because otherwise the solid filled background rectangle created will cover up everything else on the screen.

    Also, the added draw_background() function makes an effort to save and later restore the graphics state to what it was. This may not be necessary depending on your exact usage case.

    import turtle
    
    
    def draw_background(a_turtle):
        """ Draw a background rectangle. """
        ts = a_turtle.getscreen()
        canvas = ts.getcanvas()
        height = ts.getcanvas()._canvas.winfo_height()
        width = ts.getcanvas()._canvas.winfo_width()
    
        turtleheading = a_turtle.heading()
        turtlespeed = a_turtle.speed()
        penposn = a_turtle.position()
        penstate = a_turtle.pen()
    
        a_turtle.penup()
        a_turtle.speed(0)  # fastest
        a_turtle.goto(-width/2-2, -height/2+3)
        a_turtle.fillcolor(turtle.Screen().bgcolor())
        a_turtle.begin_fill()
        a_turtle.setheading(0)
        a_turtle.forward(width)
        a_turtle.setheading(90)
        a_turtle.forward(height)
        a_turtle.setheading(180)
        a_turtle.forward(width)
        a_turtle.setheading(270)
        a_turtle.forward(height)
        a_turtle.end_fill()
    
        a_turtle.penup()
        a_turtle.setposition(*penposn)
        a_turtle.pen(penstate)
        a_turtle.setheading(turtleheading)
        a_turtle.speed(turtlespeed)
    
    s = turtle.Screen()
    s.bgcolor("orange")
    
    bob = turtle.Turtle()
    draw_background(bob)
    
    ts = bob.getscreen()
    canvas = ts.getcanvas()
    
    bob.circle(250)
    
    canvas.postscript(file="turtle.eps")
    
    s.exitonclick()  # optional
    

    And here’s the actual output produced (rendered onscreen via Photoshop):

    output from eps file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to python and have been working through the examples in Swaroop
I am brand new to Python and have been working with it for a
I am new to Python and have been studying its fundementals for 3 months
hello im new to python and have been reading over the documentation and am
I'm new to Python and I have been trying to search through html with
I'm new to Python (I have been programming in Java for multiple years now
I have been working on this python issue for a while. I am in
I'm really new to C(I have been learning Cuda and wanted to learn C
I'm new to python and have hit a problem with an SQL query I'm
I am very new to python programming and have yet to buy a textbook

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.