python - "AttributeError: 'Turtle' object has no attribute 'colormode'" despite Turtle.py having colormode atttribute -
i tried running code uses turtle library on this site, shown here,
import turtle import random def main(): tlist = [] head = 0 numturtles = 10 wn = turtle.screen() wn.setup(500,500) in range(numturtles): nt = turtle.turtle() # make new turtle, initialize values nt.setheading(head) nt.pensize(2) nt.color(random.randrange(256),random.randrange(256),random.randrange(256)) nt.speed(10) wn.tracer(30,0) tlist.append(nt) # add new turtle list head = head + 360/numturtles in range(100): moveturtles(tlist,15,i) w = tlist[0] w.up() w.goto(0,40) w.write("how think ",true,"center","40pt bold") w.goto(0,-35) w.write("computer scientist",true,"center","40pt bold") def moveturtles(turtlelist,dist,angle): turtle in turtlelist: # make every turtle on list same actions. turtle.forward(dist) turtle.right(angle) main() in own python editor , got error:
turtle.turtlegraphicserror: bad color sequence: (236, 197, 141)
then, based on answer on another site, added in line before "nt.color(......)"
nt.colormode(255)
now it's showing me error
attributeerror: 'turtle' object has no attribute 'colormode'
okay, checked python library , looked contents of turtle.py. colormode() attribute there. making code able run on original site not on own computer?
the issue turtle object (nt) doesn't have colormode method. there 1 in turtle module though.
so need:
turtle.colormode(255) instead of
nt.colormode(255) edit: try clarify question in comment, suppose create module called test.py, function, , class, 'test':
# module test.py def colormode(): print("called colormode() function in module test") class test def __init__(self): pass now, use module:
import test nt = test.test() # created instance of class (like `turtle.turtle()`) # nt.colormode() # won't work, since `colormode` isn't method in `test` class test.colormode() # works, since `colormode` defined directly in `test` module
Comments
Post a Comment