[Tutor] help with colormode

Peter Otten __peter__ at web.de
Thu Apr 25 14:00:36 EDT 2019


Mark Alderson wrote:

> hi
> 
> Ihave a very small program.  I want to cycle colours.  I cant set the
> colormode from 1 to 255
> 
> tried screen.colormode(255)
> 
> tells me screen is not defined.  the program works without the colormode,
> but i want to use it.
> 
> I just change the a and b variable values to generate new art.
> 
> -------------------------------------code-----------------
> from turtle import Turtle
> t = Turtle()
> t.speed(0)
> 
> b = 180
> 
> a = 35
> 
> colormode(255)
> 
> t.color((55,55,55))
> for i in range(200):
>     t.circle(i,a)
>     t.right(b)
>     t.circle(i,a)
> 
> 
> #input('Press any key to continue...')
> 
> -------------------------------------------------------------------------
> 
> ===========error=======================
> Traceback (most recent call last):
>   File "H:\python\snowflake.py", line 9, in <module>
>     screen.colormode(255)
> NameError: name 'screen' is not defined
> ===================================

The only name you import is Turtle, so you only have that (and the built-
ins). Fortunately you can get the screen from the Turtle, so:

from turtle import Turtle

ninja = Turtle()
ninja.speed(0)

screen = ninja.screen
screen.colormode(255)

b = 180
a = 35

for i in range(200):
    ninja.color((i + 55, 55, 55))
    ninja.circle(i, a)
    ninja.right(b)
    ninja.circle(i, a)

screen.exitonclick()




More information about the Tutor mailing list