简体   繁体   English

带有海龟图形的Python花

[英]Python Flowers with Turtle(s) Graphics

I'm working with turtle graphics in my programming class in high school and the project is to make a flower following some guidelines and functions the teacher has demonstrated. 我正在高中的编程班上研究乌龟图形,该项目是按照老师演示的一些准则和功能制作的花朵。 I completed that in an hour, now I'm trying to draw multiple flowers at one time using more turtle, But I can't get the turtles to use the newly defined functions and the teacher doesn't have time to meet with me one on one to discuss how I could do it 我在一小时内完成了工作,现在我想使用更多的乌龟一次绘制多朵花,但是我无法让乌龟使用新定义的功能,而且老师没有时间与我见面讨论我该怎么做

so after about a week of searching (for something I don't know how to ask properly much less look for) I'm going to my favourite question site. 因此,经过大约一周的搜索(对于某些我不知道该如何正确询问的内容,我很少去寻找),我将转到我最喜欢的问题站点。 so if someone can help me or at least point me in the right direction I would greatly appreciate it. 因此,如果有人可以帮助我或至少指出正确的方向,我将不胜感激。

   import turtle

tod = turtle.Turtle
tina = turtle.Turtle
tony = turtle.Turtle
trixie = turtle.Turtle
tron = turtle.Turtle


def petal():
    for i in range(90):
        self.start = self.pos()
        self.fd(1)
        self.rt(1)
    self.rt(90)
    for i in range(90):
        self.fd(1)
        self.rt(1)

def stem(self):
    self.pencolor('green')
    self.fd(220)

def flowerhead(self):
    for i in range(9):
      begin_fill()
      petal()
      self.lt(230)
      end_fill()

def stempetal(self):
    self.seth(90)
    self.rt(15)
    fillcolor('green')
    begin_fill()
    petal()
    end_fill()

def flower1(self):
    flowerhead()
    stem()
    stempetal()

def flower2(self):
    flowerhead()
    self.stem()


tod.flower()

running that gives the error 运行给出错误

Traceback (most recent call last):
  File "C:\Users\first.last\Desktop\programming\trig class\testflowerclass.py", line 49, in <module>
    tod.flower()
AttributeError: type object 'Turtle' has no attribute 'flower'

屏幕截图

The area of (python) programming you are working with, but without any familiarity appears to be classes, instances and inheritance. 您正在使用的(python)编程领域,但没有任何熟悉,似乎是类,实例和继承。 There's what appears to be an entry-level tutorial on classes here: https://en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial/Classes 这里似乎有关于类的入门级教程: https : //en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial/Classes

It seems quite mean to having an assignment on this topic without having had it introduced first. 在没有先介绍该主题的情况下进行作业似乎很有意义。

You probably need to be structuring your code along the lines of: 您可能需要按照以下方式来构造代码:

from turtle import Turtle

class MyTurtle(Turtle):
    def my_method(self):
        self.method_defined_in_turtle()
        self.other_method_defined_in_turtle()

todd = MyTurtle()
todd.my_method()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM