I am trying to set the background color of my turtle graphic, is there a way can set the background color for python turtle?
Asked
Active
Viewed 9.1k times
7
-
1I didn't even know that anyone was still using that... – Ignacio Vazquez-Abrams Apr 28 '11 at 03:05
-
@Ignacio Vazquez-Abrams: you're missing a lot http://us.pycon.org/2009/conference/schedule/event/65/ – jfs Apr 28 '11 at 04:59
2 Answers
11
Use turtle.bgcolor(*args)
.
For instance:
import turtle
turtle.bgcolor("black")
or
from turtle import *
bgcolor("black")
Read the documentation at http://docs.python.org/library/turtle.html#turtle.bgcolor
-
i put turtle.bgcolor("black") , but is not working.. is there need any import?? – phhnk Apr 28 '11 at 04:03
-
THANK, gpoo.. First, i already had `from turtle import *`, so i was just add `turtle.bgcolor("black")`, but won't work. After i had see your answer, i had to `improt turtle`, too, to get it work. I wasn't know that was a different between... – phhnk Apr 28 '11 at 07:27
9
It sounds like you set the color for your turtle, not your screen. A screen will appear even if you don't set up your screen, but then it's not defined so you can't customize it. If you set up the beginning of your code, then you can customize your screen, for example:
import turtle
wn=turtle.Screen()
wn.bgcolor("black")
wn.title("This is my screen title!")

Cara
- 91
- 1
- 1
-
1Although the previous answer was accepted as the best by the question owner, actually [this answer](https://stackoverflow.com/a/33271701/9110128) is the right one. – Joey Mar 21 '19 at 23:14