这个是作品《秋天的诗》的叶子类的设计程序。
本程序运行后,叶子们会不断地往下落。下面是部分代码预览:
""" 这个模块是作品:秋天的诗的叶子类,本程序定义了Leaf类,它一诞生后会不断地下落, 到了最下边又会自动回到最上边,换个造型周而复始。 """ from turtle import * from random import * class Leaf(Turtle): """ Leaf类,继承自Turtle类 """ def __init__(self,images): Turtle.__init__(self,visible=False) self.penup() self.images = images def init(self): """进行换造型与下落的初始化定位""" def move(self): """不断地移动落叶,直到最下面""" def main(): """主要执行函数""" leaves = ['leaf0.gif','leaf1.gif','leaf2.gif','leaf3.gif'] screen = Screen() screen.delay(0) screen.setup(480,360) screen.title("落叶类的设计") [screen.addshape(im) for im in leaves] [Leaf(leaves) for x in range(10)] screen.mainloop() if __name__ == "__main__": main()
如需要查看完整源代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)