Reputation: 91
I started toying with a program I wrote back in highschool and know I don't remember what the heck I did but now every time i run the below code it gives me a nameerror, and it's been so long since I've toyed with turtle I don't know what I did wrong. You guys helped so much in getting this code to work the first time I though maybe you could help an amateur like me again
I belive it might be the python versions are now different (wrote in 3.5 trying to run in 3.6) but I'm not sure I think i just messed something up somewhere and I'm just not smart enough to figure it out
from random import randint
from turtle import Turtle, Screen
class MyTurtle(Turtle):
def petals(self, size=30, count=8, speed=100):
if size == 30:
self.begin_fill()
if size > 0: # drawing leading edge of petal
self.fd(3)
self.rt(3)
screen.ontimer(lambda: self.petals(size - 1, count, speed), speed)
return
if size == 0: # switch to other edge of petal
self.rt(90)
if size > -30: # drawing trailing edge of petal
self.fd(3)
self.rt(3)
screen.ontimer(lambda: self.petals(size - 1, count, speed), speed)
return
self.end_fill() # finish this petal
self.lt(230) # prepare for the next petal
if count > 0: # drawing the next petal
screen.ontimer(lambda: self.petals(count=count - 1, speed=speed), speed)
return
self.hideturtle() # finished drawing
def flowerhead(self):
self.pencolor('red') #outlines the flowerpetals in red to see easier
self.petals(speed=9)
# self.petals(speed=randint(50, 250))
def flower1():
todd.color('green', 'blue')
todd.goto(0, -270)
todd.penup()
todd.showturtle()
todd.goto(0,0)
todd.pendown()
todd.flowerhead()
def flower2():
tony.color('green', 'purple')
tony.penup()
tony.goto(0, -200)
tony.pendown()
tony.showturtle()
tony.goto(80, -15)
tony.seth(0)
tony.flowerhead()
def flower3():
tina.color('green', 'turquoise')
tina.penup()
tina.goto(0, -200)
tina.pendown()
tina.showturtle()
tina.goto(-80, -15)
tina.seth(90)
tina.flowerhead()
def flower4():
tiny.color('green', 'black')
tiny.penup()
tiny.goto(0, -200)
tiny.pendown()
tiny.showturtle()
tiny.goto(160, -25)
tiny.seth(90)
tiny.flowerhead()
def flower5():
tweeny.color('green', 'pink')
tweeny.penup()
tweeny.goto(0, -200)
tweeny.pendown()
tweeny.showturtle()
tweeny.goto(-160, -25)
tweeny.seth(90)
tweeny.flowerhead()
def writing():
teacher.penup()
teacher.setpos(0, 120)
teacher.pendown()
teacher.color('red')
teacher.write('test', align='center', font=('Times New Roman', 30, 'normal'))
tony = MyTurtle(shape='turtle', visible=False)
todd = MyTurtle(shape='turtle', visible=False)
tina = MyTurtle(shape='turtle', visible=False)
tiny = MyTurtle(shape='turtle', visible=False)
tweeny = MyTurtle(shape='turtle', visible=False)
teacher = MyTurtle(shape='turtle', visible=False)
screen = getScreen()
screen.title('I am epic')
screen.delay(0)
screen.ontimer(flower2, 6500)
screen.ontimer(flower4, 0)
screen.ontimer(flower3, 6500)
screen.ontimer(flower5, 0)
screen.ontimer(flower1, 13000)
screen.ontimer(writing, 26000)
screen.mainloop()
the line that gives me the error is
screen = getScreen()
Traceback (most recent call last):
File "E:\programming\trig class\Multiple flowers runnig at once.py", line 106, in <module>
screen = getscreen()
NameError: name 'getscreen' is not defined
Like I said, i think it's the versions but I'd appreciate a second, third or even fourth opinion I'm just a student trying to learn how to not be stupid
Upvotes: 0
Views: 1824
Reputation: 107
you defined scree as get screen like this:
screen=getScreen()
this is an old version of calling the screen try using the new version which is
screen = turtle.Screen()
Upvotes: 1